diff options
author | Maxim Devaev <[email protected]> | 2024-10-21 17:46:59 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2024-10-21 17:46:59 +0300 |
commit | cda32a083faf3e7326cfe317336e473c905c6dfd (patch) | |
tree | 19445e4098d4603f3b2cd296504a648110712af1 /kvmd/aiomulti.py | |
parent | b67a2325842a6f407d3935f8445d50cb8bf307f2 (diff) |
new events model
Diffstat (limited to 'kvmd/aiomulti.py')
-rw-r--r-- | kvmd/aiomulti.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/kvmd/aiomulti.py b/kvmd/aiomulti.py index 653651cb..a4537204 100644 --- a/kvmd/aiomulti.py +++ b/kvmd/aiomulti.py @@ -59,14 +59,25 @@ def queue_get_last_sync( # pylint: disable=invalid-name # ===== class AioProcessNotifier: def __init__(self) -> None: - self.__queue: "multiprocessing.Queue[None]" = multiprocessing.Queue() - - def notify(self) -> None: - self.__queue.put_nowait(None) - - async def wait(self) -> None: - while not (await queue_get_last(self.__queue, 0.1))[0]: - pass + self.__queue: "multiprocessing.Queue[int]" = multiprocessing.Queue() + + def notify(self, mask: int=0) -> None: + self.__queue.put_nowait(mask) + + async def wait(self) -> int: + while True: + mask = await aiotools.run_async(self.__get) + if mask >= 0: + return mask + + def __get(self) -> int: + try: + mask = self.__queue.get(timeout=0.1) + while not self.__queue.empty(): + mask |= self.__queue.get() + return mask + except queue.Empty: + return -1 # ===== |