summaryrefslogtreecommitdiff
path: root/kvmd/plugins/msd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-05 09:26:55 +0300
committerDevaev Maxim <[email protected]>2020-09-05 09:26:55 +0300
commit482eeec3e715bbbd35dfafa4d8180d897fb549bd (patch)
treeda3eca92d126e6ee549d4a14a5d342f426d2aa49 /kvmd/plugins/msd
parente162d84d5622f18a5afeddea0da19498ee25dc23 (diff)
common background systasks
Diffstat (limited to 'kvmd/plugins/msd')
-rw-r--r--kvmd/plugins/msd/otg/__init__.py31
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: