Skip to content

Commit

Permalink
Add threading for container removing in case of detach
Browse files Browse the repository at this point in the history
  • Loading branch information
milanbalazs committed Sep 14, 2024
1 parent 7f1c776 commit 63b5184
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions podman/domain/containers_run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Mixin to provide Container run() method."""

import logging
import threading
from contextlib import suppress
from typing import Generator, Iterator, List, Union

Expand Down Expand Up @@ -67,7 +68,20 @@ def run(
container.wait(condition=["running", "exited"])
container.reload()

def remove_container(container_object: Container) -> None:
"""
Wait the container to finish and remove it.
Args:
container_object: Container object
"""
container_object.wait() # Wait for the container to finish
container_object.remove() # Remove the container

if kwargs.get("detach", False):
if remove:
# Start a background thread to remove the container after finishing
threading.Thread(target=remove_container, args=(container,)).start()
return container

with suppress(KeyError):
Expand Down

0 comments on commit 63b5184

Please sign in to comment.