Always cancel container on teardown

contain_mkts
Tyler Goodlet 2022-06-26 13:07:25 -04:00
parent 27c523ca74
commit e45cb9d08a
1 changed files with 9 additions and 15 deletions

View File

@ -211,10 +211,13 @@ class Container:
try: try:
log.info(f'Polling for container shutdown:\n{cid}') log.info(f'Polling for container shutdown:\n{cid}')
self.cntr.wait(
timeout=0.1, if self.cntr.status not in {'exited', 'not-running'}:
condition='not-running', self.cntr.wait(
) timeout=0.1,
condition='not-running',
)
break break
except ( except (
@ -227,7 +230,7 @@ class Container:
docker.errors.APIError, docker.errors.APIError,
ConnectionError, ConnectionError,
): ):
log.exception(f'Docker connection failure') log.exception('Docker connection failure')
break break
else: else:
delay = time.time() - start delay = time.time() - start
@ -273,8 +276,6 @@ async def open_ahabd(
with trio.move_on_after(1): with trio.move_on_after(1):
found = await cntr.process_logs_until(start_msg) found = await cntr.process_logs_until(start_msg)
# "launching tcp listener for all services...",
# )
if not found and cntr not in client.containers.list(): if not found and cntr not in client.containers.list():
raise RuntimeError( raise RuntimeError(
@ -294,17 +295,10 @@ async def open_ahabd(
# callers to have root perms? # callers to have root perms?
await trio.sleep_forever() await trio.sleep_forever()
except ( finally:
BaseException,
# trio.Cancelled,
# KeyboardInterrupt,
):
with trio.CancelScope(shield=True): with trio.CancelScope(shield=True):
await cntr.cancel(stop_msg) await cntr.cancel(stop_msg)
raise
async def start_ahab( async def start_ahab(
service_name: str, service_name: str,