Skip to content

Commit dcb6cdb

Browse files
authored
Merge pull request #858 from breca/asyncio_compat
Replaces asyncio timeout with bespoke timeout function
2 parents d468f85 + 0f693ee commit dcb6cdb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

podman_compose.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,23 @@ def flat_deps(services, with_extends=False):
11141114
rec_deps(services, name)
11151115

11161116

1117+
async def wait_with_timeout(coro, timeout):
1118+
"""
1119+
Asynchronously waits for the given coroutine to complete with a timeout.
1120+
1121+
Args:
1122+
coro: The coroutine to wait for.
1123+
timeout (int or float): The maximum number of seconds to wait for.
1124+
1125+
Raises:
1126+
TimeoutError: If the coroutine does not complete within the specified timeout.
1127+
"""
1128+
try:
1129+
return await asyncio.wait_for(coro, timeout)
1130+
except asyncio.TimeoutError as exc:
1131+
raise TimeoutError from exc
1132+
1133+
11171134
###################
11181135
# podman and compose classes
11191136
###################
@@ -1211,8 +1228,7 @@ async def format_out(stdout):
12111228
log("Sending termination signal")
12121229
p.terminate()
12131230
try:
1214-
async with asyncio.timeout(10):
1215-
exit_code = await p.wait()
1231+
exit_code = await wait_with_timeout(p.wait(), 10)
12161232
except TimeoutError:
12171233
log("container did not shut down after 10 seconds, killing")
12181234
p.kill()

0 commit comments

Comments
 (0)