summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-08-05 15:07:17 +0300
committerMaxim Devaev <[email protected]>2022-08-05 15:07:17 +0300
commiteeaeebf7c76385536eb8f5daaea5f21bda18b735 (patch)
tree5c8008edd4e4fea85da5e7e16f32389ede95f56a
parent9ee63aba3ead6493acd01c89ffe17c503cdb4017 (diff)
shield some finally ops
-rw-r--r--kvmd/plugins/msd/otg/__init__.py32
-rw-r--r--kvmd/plugins/msd/relay/__init__.py10
2 files changed, 34 insertions, 8 deletions
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py
index 96ef9289..2d556048 100644
--- a/kvmd/plugins/msd/otg/__init__.py
+++ b/kvmd/plugins/msd/otg/__init__.py
@@ -354,9 +354,17 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
yield self.__reader
finally:
- await self.__close_reader()
+ # FIXME: Перехват важен потому что по какой-то причине await
+ # во вложенных finally путаются и выполняются не по порядку
+ try:
+ await asyncio.shield(self.__close_reader())
+ except asyncio.CancelledError:
+ pass
finally:
- await self.__notifier.notify()
+ try:
+ await asyncio.shield(self.__notifier.notify())
+ except asyncio.CancelledError:
+ pass
@contextlib.asynccontextmanager
async def write_image(self, name: str, size: int, remove_incomplete: Optional[bool]) -> AsyncGenerator[MsdFileWriter, None]:
@@ -398,13 +406,25 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
os.remove(path)
except Exception:
pass
- await self.__close_writer()
- await self.__remount_rw(False, fatal=False)
+ try:
+ await asyncio.shield(self.__close_writer())
+ except asyncio.CancelledError:
+ pass
+ try:
+ await asyncio.shield(self.__remount_rw(False, fatal=False))
+ except asyncio.CancelledError:
+ pass
finally:
# Между закрытием файла и эвентом айнотифи состояние может быть не обновлено,
# так что форсим обновление вручную, чтобы получить актуальное состояние.
- await self.__reload_state()
- await self.__notifier.notify()
+ try:
+ await asyncio.shield(self.__reload_state())
+ except asyncio.CancelledError:
+ pass
+ try:
+ await asyncio.shield(self.__notifier.notify())
+ except asyncio.CancelledError:
+ pass
@aiotools.atomic
async def remove(self, name: str) -> None:
diff --git a/kvmd/plugins/msd/relay/__init__.py b/kvmd/plugins/msd/relay/__init__.py
index 14f903f1..9e507556 100644
--- a/kvmd/plugins/msd/relay/__init__.py
+++ b/kvmd/plugins/msd/relay/__init__.py
@@ -249,8 +249,14 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
yield self.__device_writer
await self.__write_image_info(True)
finally:
- await self.__close_device_writer()
- await self.__load_device_info()
+ try:
+ await asyncio.shield(self.__close_device_writer())
+ except asyncio.CancelledError:
+ pass
+ try:
+ await asyncio.shield(self.__load_device_info())
+ except asyncio.CancelledError:
+ pass
@aiotools.atomic
async def remove(self, name: str) -> None: