diff options
Diffstat (limited to 'kvmd/aiotools.py')
-rw-r--r-- | kvmd/aiotools.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py index 574c8bc7..98a2a524 100644 --- a/kvmd/aiotools.py +++ b/kvmd/aiotools.py @@ -20,6 +20,7 @@ # ========================================================================== # +import os import asyncio import functools import contextlib @@ -34,6 +35,9 @@ from typing import AsyncGenerator from typing import TypeVar from typing import Any +import aiofiles +import aiofiles.base + from . import aioregion from .logging import get_logger @@ -118,3 +122,10 @@ async def unlock_only_on_exception(lock: asyncio.Lock) -> AsyncGenerator[None, N except: # noqa: E722 lock.release() raise + + +# ===== +async def afile_write_now(afile: aiofiles.base.AiofilesContextManager, data: bytes) -> None: + await afile.write(data) + await afile.flush() + await run_async(os.fsync, afile.fileno()) |