diff options
author | Maxim Devaev <[email protected]> | 2023-05-04 12:37:05 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-05-04 12:37:05 +0300 |
commit | b5353e63cd52b0d98e7a56acc5c8fbfc6ad8b3ee (patch) | |
tree | 3176f1a738b9533e6f3a28b132e4501a6f97f991 /kvmd | |
parent | b5d67314977a7e475fac164446031ca7c83b8bc4 (diff) |
python 3.11 fixes
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/aiotools.py | 7 | ||||
-rw-r--r-- | kvmd/apps/kvmd/streamer.py | 5 | ||||
-rw-r--r-- | kvmd/inotify.py | 5 | ||||
-rw-r--r-- | kvmd/plugins/ugpio/tesmart.py | 12 |
4 files changed, 22 insertions, 7 deletions
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py index c87e8268..51ad6ca8 100644 --- a/kvmd/aiotools.py +++ b/kvmd/aiotools.py @@ -202,7 +202,7 @@ async def wait_infinite() -> None: await asyncio.sleep(3600) -async def wait_first(*aws: Awaitable) -> tuple[set[asyncio.Task], set[asyncio.Task]]: +async def wait_first(*aws: (asyncio.Future | asyncio.Task)) -> tuple[set[asyncio.Task], set[asyncio.Task]]: return (await asyncio.wait(list(aws), return_when=asyncio.FIRST_COMPLETED)) @@ -242,7 +242,10 @@ class AioNotifier: await self.__queue.get() else: try: - await asyncio.wait_for(self.__queue.get(), timeout=timeout) + await asyncio.wait_for( + asyncio.ensure_future(self.__queue.get()), + timeout=timeout, + ) except asyncio.TimeoutError: return # False while not self.__queue.empty(): diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index 3cdb301a..ce4db816 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -329,7 +329,10 @@ class Streamer: # pylint: disable=too-many-instance-attributes if waiter_task is None: waiter_task = asyncio.create_task(self.__notifier.wait()) - if waiter_task in (await aiotools.wait_first(asyncio.sleep(self.__state_poll), waiter_task))[0]: + if waiter_task in (await aiotools.wait_first( + asyncio.ensure_future(asyncio.sleep(self.__state_poll)), + waiter_task, + ))[0]: waiter_task = None # ===== diff --git a/kvmd/inotify.py b/kvmd/inotify.py index b66ca443..c157c1ca 100644 --- a/kvmd/inotify.py +++ b/kvmd/inotify.py @@ -215,7 +215,10 @@ class Inotify: async def get_event(self, timeout: float) -> (InotifyEvent | None): assert timeout > 0 try: - return (await asyncio.wait_for(self.__events_queue.get(), timeout=timeout)) + return (await asyncio.wait_for( + asyncio.ensure_future(self.__events_queue.get()), + timeout=timeout, + )) except asyncio.TimeoutError: return None diff --git a/kvmd/plugins/ugpio/tesmart.py b/kvmd/plugins/ugpio/tesmart.py index c7e410f6..1e869ed2 100644 --- a/kvmd/plugins/ugpio/tesmart.py +++ b/kvmd/plugins/ugpio/tesmart.py @@ -137,8 +137,14 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute assert self.__writer is not None try: self.__writer.write(b"\xAA\xBB\x03%s\xEE" % (cmd)) - await asyncio.wait_for(self.__writer.drain(), timeout=self.__timeout) - return (await asyncio.wait_for(self.__reader.readexactly(6), timeout=self.__timeout))[4] + await asyncio.wait_for( + asyncio.ensure_future(self.__writer.drain()), + timeout=self.__timeout, + ) + return (await asyncio.wait_for( + asyncio.ensure_future(self.__reader.readexactly(6)), + timeout=self.__timeout, + ))[4] except Exception as err: get_logger(0).error("Can't send command to TESmart KVM [%s]:%d: %s", self.__host, self.__port, tools.efmt(err)) @@ -155,7 +161,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute async def __ensure_device_net(self) -> None: try: (self.__reader, self.__writer) = await asyncio.wait_for( - asyncio.open_connection(self.__host, self.__port), + asyncio.ensure_future(asyncio.open_connection(self.__host, self.__port)), timeout=self.__timeout, ) except Exception as err: |