Skip to content

Commit

Permalink
Merge pull request #858 from breca/asyncio_compat
Browse files Browse the repository at this point in the history
Replaces asyncio timeout with bespoke timeout function
  • Loading branch information
p12tic authored Mar 9, 2024
2 parents d468f85 + 0f693ee commit dcb6cdb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
###################
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit dcb6cdb

Please sign in to comment.