Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces asyncio timeout with bespoke timeout function #858

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading