From fde7995cb8bd574a9fe3df6ef6daa5a5fa2df1b7 Mon Sep 17 00:00:00 2001 From: Bas Zoetekouw Date: Sat, 9 Mar 2024 17:06:41 +0100 Subject: [PATCH] Fix python < 3.11 compatibility Signed-off-by: Bas Zoetekouw --- podman_compose.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/podman_compose.py b/podman_compose.py index 3099e2d..18bdf32 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -2298,6 +2298,14 @@ async def compose_up(compose: PodmanCompose, args): ) ) + def _task_cancelled(task: Task) -> bool: + if task.cancelled(): + return True + # Task.cancelling() is new in python 3.11 + if sys.version_info >= (3, 11) and task.cancelling(): + return True + return False + exit_code = 0 exiting = False while tasks: @@ -2308,7 +2316,9 @@ async def compose_up(compose: PodmanCompose, args): # cause the status to overwrite. Sleeping for 1 seems to fix this and make it match # docker-compose await asyncio.sleep(1) - _ = [_.cancel() for _ in tasks if not _.cancelling() and not _.cancelled()] + for t in tasks: + if not _task_cancelled(t): + t.cancel() t: Task exiting = True for t in done: