From 0f693ee584ac1f802166d8e3890d0f62d4fe6ca4 Mon Sep 17 00:00:00 2001
From: Brett Calliss <brett@obligatory.email>
Date: Mon, 26 Feb 2024 08:34:41 +1100
Subject: [PATCH] Replaces asyncio timeout with bespoke timeout function

Signed-off-by: Brett Calliss <brett@obligatory.email>
---
 podman_compose.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/podman_compose.py b/podman_compose.py
index 1ae32989..d4145b73 100755
--- a/podman_compose.py
+++ b/podman_compose.py
@@ -1114,6 +1114,23 @@ def flat_deps(services, with_extends=False):
         rec_deps(services, name)
 
 
+async def wait_with_timeout(coro, timeout):
+    """
+    Asynchronously waits for the given coroutine to complete with a timeout.
+
+    Args:
+        coro: The coroutine to wait for.
+        timeout (int or float): The maximum number of seconds to wait for.
+
+    Raises:
+        TimeoutError: If the coroutine does not complete within the specified timeout.
+    """
+    try:
+        return await asyncio.wait_for(coro, timeout)
+    except asyncio.TimeoutError as exc:
+        raise TimeoutError from exc
+
+
 ###################
 # podman and compose classes
 ###################
@@ -1211,8 +1228,7 @@ async def format_out(stdout):
                 log("Sending termination signal")
                 p.terminate()
                 try:
-                    async with asyncio.timeout(10):
-                        exit_code = await p.wait()
+                    exit_code = await wait_with_timeout(p.wait(), 10)
                 except TimeoutError:
                     log("container did not shut down after 10 seconds, killing")
                     p.kill()