From e45cb9d08aac7cd1a597355e026553baf45abc9e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 26 Jun 2022 13:07:25 -0400 Subject: [PATCH] Always cancel container on teardown --- piker/data/_ahab.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/piker/data/_ahab.py b/piker/data/_ahab.py index 7323a08d..98b3b41f 100644 --- a/piker/data/_ahab.py +++ b/piker/data/_ahab.py @@ -211,10 +211,13 @@ class Container: try: log.info(f'Polling for container shutdown:\n{cid}') - self.cntr.wait( - timeout=0.1, - condition='not-running', - ) + + if self.cntr.status not in {'exited', 'not-running'}: + self.cntr.wait( + timeout=0.1, + condition='not-running', + ) + break except ( @@ -227,7 +230,7 @@ class Container: docker.errors.APIError, ConnectionError, ): - log.exception(f'Docker connection failure') + log.exception('Docker connection failure') break else: delay = time.time() - start @@ -273,8 +276,6 @@ async def open_ahabd( with trio.move_on_after(1): found = await cntr.process_logs_until(start_msg) - # "launching tcp listener for all services...", - # ) if not found and cntr not in client.containers.list(): raise RuntimeError( @@ -294,17 +295,10 @@ async def open_ahabd( # callers to have root perms? await trio.sleep_forever() - except ( - BaseException, - # trio.Cancelled, - # KeyboardInterrupt, - ): - + finally: with trio.CancelScope(shield=True): await cntr.cancel(stop_msg) - raise - async def start_ahab( service_name: str,