Skip to content

Commit 744a6c4

Browse files
author
David Erb
committed
fixes context shutdown
1 parent 250a73c commit 744a6c4

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/dls_servbase_lib/datafaces/context.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,23 @@ async def aenter(self) -> None:
6363
await self.server.activate()
6464

6565
# ----------------------------------------------------------------------------------------
66-
async def aexit(self, type, value, traceback) -> None:
66+
async def aexit(self, type=None, value=None, traceback=None):
6767
"""
6868
Asyncio context exit.
6969
7070
Stop service if one was started and releases any client resources.
7171
"""
72+
logger.debug(f"[DISSHU] {thing_type} aexit")
7273

7374
if self.server is not None:
7475
start_as = self.context_specification.get("start_as")
7576

7677
if start_as == "process":
77-
logger.info(
78-
"[DISSHU] in context exit, sending shutdown to client process"
79-
)
80-
# Put in request to shutdown the server.
81-
await self.server.client_shutdown()
82-
logger.info("[DISSHU] in context exit, sent shutdown to client process")
78+
# The server associated with this context is running?
79+
if await self.is_process_alive():
80+
logger.debug(f"[DISSHU] {thing_type} calling client_shutdown")
81+
# Put in request to shutdown the server.
82+
await self.server.client_shutdown()
8383

8484
if start_as == "coro":
8585
await self.server.direct_shutdown()

src/dls_servbase_lib/guis/context.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,23 @@ async def aenter(self):
3737
await self.server.start_process()
3838

3939
# ----------------------------------------------------------------------------------------
40-
async def aexit(self, type, value, traceback):
41-
""" """
40+
async def aexit(self, type=None, value=None, traceback=None):
41+
"""
42+
Asyncio context exit.
43+
44+
Stop service if one was started and releases any client resources.
45+
"""
46+
logger.debug(f"[DISSHU] {thing_type} aexit")
4247

4348
if self.server is not None:
44-
# Put in request to shutdown the server.
45-
await self.server.client_shutdown()
49+
start_as = self.context_specification.get("start_as")
50+
51+
if start_as == "process":
52+
# The server associated with this context is running?
53+
if await self.is_process_alive():
54+
logger.debug(f"[DISSHU] {thing_type} calling client_shutdown")
55+
# Put in request to shutdown the server.
56+
await self.server.client_shutdown()
4657

47-
# Release a client connection if we had one.
48-
await self.server.close_client_session()
58+
if start_as == "coro":
59+
await self.server.direct_shutdown()

0 commit comments

Comments
 (0)