Skip to content

Commit 4d1b9c2

Browse files
authored
Merge pull request #221 from ezmsg-org/fix/219-alternate
Wrap shutdown_units().result() and context.revert().result() with whi…
2 parents 0174559 + 482c942 commit 4d1b9c2

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/ezmsg/core/backendprocess.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,24 @@ async def shutdown_units() -> None:
309309
else:
310310
unit.shutdown() # type: ignore
311311

312-
asyncio.run_coroutine_threadsafe(shutdown_units(), loop=loop).result()
313-
314-
# for cache in MessageCache.values():
315-
# cache.clear()
312+
shutdown_future = asyncio.run_coroutine_threadsafe(shutdown_units(), loop=loop)
313+
try:
314+
shutdown_future.result()
315+
except KeyboardInterrupt:
316+
logger.warning("Interrupted during unit shutdown. This may indicate units with slow shutdown methods."
317+
"Re-trying... Press ctrl-c again to terminate immediately.")
318+
shutdown_future.result()
316319

317-
asyncio.run_coroutine_threadsafe(context.revert(), loop=loop).result()
320+
revert_future = asyncio.run_coroutine_threadsafe(context.revert(), loop=loop)
321+
try:
322+
revert_future.result()
323+
except KeyboardInterrupt:
324+
logger.warning("Interrupted during context revert."
325+
"Re-trying... (will timeout in 10 seconds)")
326+
try:
327+
revert_future.result(timeout=10.0)
328+
except TimeoutError:
329+
logger.warning("Timed out waiting for retry on context revert")
318330

319331
logger.debug(f"Remaining tasks in event loop = {asyncio.all_tasks(loop)}")
320332

0 commit comments

Comments
 (0)