add try-except block to handle error in case of shutdown error

Signed-off-by: Mohammad Kazemi <mokazemi@disroot.org>
This commit is contained in:
Mohammad Kazemi 2025-02-24 15:18:45 +03:30
parent 3973c476c4
commit b748c2666c

View File

@ -2780,11 +2780,16 @@ async def compose_up(compose: PodmanCompose, args):
tasks = set()
async def handle_sigint():
log.info("Caught SIGINT, shutting down...")
down_args = argparse.Namespace(**dict(args.__dict__, volumes=False))
await compose.commands["down"](compose, down_args)
for task in tasks:
task.cancel()
log.info("Caught SIGINT or Ctrl+C, shutting down...")
try:
log.info("Shutting down gracefully, please wait...")
down_args = argparse.Namespace(**dict(args.__dict__, volumes=False))
await compose.commands["down"](compose, down_args)
except Exception as e:
log.error(f"Error during shutdown: {e}")
finally:
for task in tasks:
task.cancel()
if sys.platform != 'win32':
loop = asyncio.get_event_loop()