diff options
Diffstat (limited to 'kvmd/plugins/msd/otg/__init__.py')
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index 25585302..8d1cc1b2 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -206,29 +206,16 @@ 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: - if inotify_task.cancelled(): - break - if inotify_task.done(): - RuntimeError("Inotify task is dead") - - state = await self.get_state() - if state != prev_state: - yield state - prev_state = state - - 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() - await inotify_task + while True: + state = await self.get_state() + if state != prev_state: + yield state + prev_state = state + await self.__state_notifier.wait() + + async def systask(self) -> None: + await self.__watch_inotify() @aiotools.atomic async def reset(self) -> None: |