Skip to content

Commit

Permalink
fixes context shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
David Erb committed Jun 8, 2023
1 parent 250a73c commit 744a6c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/dls_servbase_lib/datafaces/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ async def aenter(self) -> None:
await self.server.activate()

# ----------------------------------------------------------------------------------------
async def aexit(self, type, value, traceback) -> None:
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:
start_as = self.context_specification.get("start_as")

if start_as == "process":
logger.info(
"[DISSHU] in context exit, sending shutdown to client process"
)
# Put in request to shutdown the server.
await self.server.client_shutdown()
logger.info("[DISSHU] in context exit, sent shutdown to client process")
# 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 start_as == "coro":
await self.server.direct_shutdown()
Expand Down
23 changes: 17 additions & 6 deletions src/dls_servbase_lib/guis/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,23 @@ 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:
# Put in request to shutdown the server.
await self.server.client_shutdown()
start_as = self.context_specification.get("start_as")

if start_as == "process":
# 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()

# Release a client connection if we had one.
await self.server.close_client_session()
if start_as == "coro":
await self.server.direct_shutdown()

0 comments on commit 744a6c4

Please sign in to comment.