diff options
author | Devaev Maxim <[email protected]> | 2020-03-15 02:42:10 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-03-15 02:42:10 +0300 |
commit | 5b58af4d6f433fcbf16e967404a5cd85a85eefba (patch) | |
tree | 9a40dfc055f59494019eb50fd0e34b232669a665 /kvmd/plugins | |
parent | eb419822cde3c5c482196664a1fd8aed5236f098 (diff) |
proper usage of asyncio.wait() for first completed
Diffstat (limited to 'kvmd/plugins')
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index a65f989f..97a49dc0 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -206,6 +206,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes async def poll_state(self) -> AsyncGenerator[Dict, None]: inotify_task = asyncio.create_task(self.__watch_inotify()) + waiter_task: Optional[asyncio.Task] = None prev_state: Dict = {} try: while True: @@ -219,10 +220,10 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes yield state prev_state = state - await asyncio.wait([ - inotify_task, - self.__state_notifier.wait(), - ], return_when=asyncio.FIRST_COMPLETED) + if waiter_task is None: + waiter_task = asyncio.create_task(self.__state_notifier.wait()) + if waiter_task in (await aiotools.wait_first(inotify_task, waiter_task))[0]: + waiter_task = None finally: if not inotify_task.done(): inotify_task.cancel() |