using shield_fg()

This commit is contained in:
Maxim Devaev 2022-08-07 19:18:23 +03:00
parent 1d4b39ef1b
commit fdc3edfa79
7 changed files with 16 additions and 30 deletions

View File

@ -66,7 +66,7 @@ class ExtrasInfoSubmanager(BaseInfoSubmanager):
return None return None
finally: finally:
if sui is not None: if sui is not None:
await asyncio.shield(sui.close()) await aiotools.shield_fg(sui.close())
def __get_extras_path(self, *parts: str) -> str: def __get_extras_path(self, *parts: str) -> str:
return os.path.join(self.__global_config.kvmd.info.extras, *parts) return os.path.join(self.__global_config.kvmd.info.extras, *parts)

View File

@ -101,7 +101,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
try: try:
await aiotools.wait_first(*tasks) await aiotools.wait_first(*tasks)
finally: finally:
await asyncio.shield(self.__cleanup(tasks)) await aiotools.shield_fg(self.__cleanup(tasks))
async def __cleanup(self, tasks: List[asyncio.Task]) -> None: async def __cleanup(self, tasks: List[asyncio.Task]) -> None:
for task in tasks: for task in tasks:

View File

@ -147,7 +147,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
fb_sender=self.__fb_sender_task_loop(), fb_sender=self.__fb_sender_task_loop(),
) )
finally: finally:
await asyncio.shield(self.__cleanup()) await aiotools.shield_fg(self.__cleanup())
async def __cleanup(self) -> None: async def __cleanup(self) -> None:
if self.__kvmd_session: if self.__kvmd_session:
@ -498,7 +498,7 @@ class VncServer: # pylint: disable=too-many-instance-attributes
except Exception: except Exception:
logger.exception("%s [entry]: Unhandled exception in client task", remote) logger.exception("%s [entry]: Unhandled exception in client task", remote)
finally: finally:
await asyncio.shield(cleanup_client(writer)) await aiotools.shield_fg(cleanup_client(writer))
self.__handle_client = handle_client self.__handle_client = handle_client

View File

@ -170,7 +170,7 @@ class KvmdClientWs:
if writer_task: if writer_task:
writer_task.cancel() writer_task.cancel()
try: try:
await asyncio.shield(self.__ws.close()) await aiotools.shield_fg(self.__ws.close())
except Exception: except Exception:
pass pass
finally: finally:

View File

@ -61,6 +61,8 @@ from .errors import IsBusyError
from .validators import ValidatorError from .validators import ValidatorError
from . import aiotools
# ===== # =====
class HttpError(Exception): class HttpError(Exception):
@ -352,7 +354,7 @@ class HttpServer:
await self._on_ws_opened() await self._on_ws_opened()
yield ws yield ws
finally: finally:
await asyncio.shield(self.__close_ws(ws)) await aiotools.shield_fg(self.__close_ws(ws))
async def _ws_loop(self, ws: WsSession) -> WebSocketResponse: async def _ws_loop(self, ws: WsSession) -> WebSocketResponse:
logger = get_logger() logger = get_logger()

View File

@ -354,12 +354,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
yield self.__reader yield self.__reader
finally: finally:
# FIXME: Перехват важен потому что по какой-то причине await await aiotools.shield_fg(self.__close_reader())
# во вложенных finally путаются и выполняются не по порядку
try:
await asyncio.shield(self.__close_reader())
except asyncio.CancelledError:
pass
finally: finally:
self.__notifier.notify() self.__notifier.notify()
@ -404,20 +399,13 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
except Exception: except Exception:
pass pass
try: try:
await asyncio.shield(self.__close_writer()) await aiotools.shield_fg(self.__close_writer())
except asyncio.CancelledError: finally:
pass await aiotools.shield_fg(self.__remount_rw(False, fatal=False))
try:
await asyncio.shield(self.__remount_rw(False, fatal=False))
except asyncio.CancelledError:
pass
finally: finally:
# Между закрытием файла и эвентом айнотифи состояние может быть не обновлено, # Между закрытием файла и эвентом айнотифи состояние может быть не обновлено,
# так что форсим обновление вручную, чтобы получить актуальное состояние. # так что форсим обновление вручную, чтобы получить актуальное состояние.
try: await aiotools.shield_fg(self.__reload_state())
await asyncio.shield(self.__reload_state())
except asyncio.CancelledError:
pass
@aiotools.atomic @aiotools.atomic
async def remove(self, name: str) -> None: async def remove(self, name: str) -> None:

View File

@ -250,13 +250,9 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
await self.__write_image_info(True) await self.__write_image_info(True)
finally: finally:
try: try:
await asyncio.shield(self.__close_device_writer()) await aiotools.shield_fg(self.__close_device_writer())
except asyncio.CancelledError: finally:
pass await aiotools.shield_fg(self.__load_device_info())
try:
await asyncio.shield(self.__load_device_info())
except asyncio.CancelledError:
pass
@aiotools.atomic @aiotools.atomic
async def remove(self, name: str) -> None: async def remove(self, name: str) -> None: