From 72190cd17bac15842f3b35e7aa2eb1b1fec28a02 Mon Sep 17 00:00:00 2001 From: David Erb Date: Thu, 8 Jun 2023 14:34:10 +0100 Subject: [PATCH] fixes context exit --- src/echolocator_lib/guis/context.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/echolocator_lib/guis/context.py b/src/echolocator_lib/guis/context.py index 1aec2f9..16671e7 100644 --- a/src/echolocator_lib/guis/context.py +++ b/src/echolocator_lib/guis/context.py @@ -38,15 +38,21 @@ async def aenter(self): await self.server.start_process() # ---------------------------------------------------------------------------------------- - async def aexit(self, type, value, traceback): - """ """ + async def aexit(self, type=None, value=None, traceback=None): + """ + Asyncio context exit. + + Stop service if one was started and releases any client resources. + """ logger.debug(f"[DISSHU] {thing_type} aexit") if self.server is not None: if self.context_specification.get("start_as") == "process": - logger.debug(f"[DISSHU] {thing_type} calling client_shutdown") - # Put in request to shutdown the server. - await self.server.client_shutdown() + # The server associated with this context is running? + if await self.is_process_alive(): + logger.debug(f"[DISSHU] {thing_type} calling client_shutdown") + # Put in request to shutdown the server. + await self.server.client_shutdown() if self.context_specification.get("start_as") == "coro": await self.server.direct_shutdown()