Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Feature: Timeout on command execution

Offen
#972 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 12 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
42/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
docker, python
Bereich
devops, testing

Rechercherichtung

Beginne bei DockerContainer.exec und docs/features/executing_commands.md und vergleiche anschließend das dokumentierte Timeout-Beispiel mit docker-py Container.exec_run und dessen Einschränkungen. Abgeschlossen ist die Aufgabe, wenn exec() ein Timeout akzeptiert, bei Überschreitung der Frist TimeoutError auslöst und den Testlauf nicht auf unbestimmte Zeit blockiert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

🚀 enhancement

What are you trying to do?

The DockerContainer.exec() method does not support a timeout parameter, even though the documentation explicitly describes this functionality:

with GenericContainer("alpine:latest") as container:
    try:
        exit_code, output = container.exec(
            ["sleep", "10"],
            timeout=5  # Timeout in seconds
        )
    except TimeoutError:
        print("Command timed out")

However, the actual implementation simply forwards to docker-py's exec_run without accepting any additional keyword arguments:

def exec(self, command: Union[str, list[str]]) -> ExecResult:
    if not self._container:
        raise ContainerStartException("Container should be started before executing a command")
    return self._container.exec_run(command)

We'd like exec() to support a timeout so that commands that hang or take too long don't block test runs indefinitely.

Why should it be done this way?

Without a timeout, any exec() call that hangs (e.g. a command waiting on a resource that never becomes available) will block the test process forever with no way to recover other than killing the process externally.

Unfortunately this isn't a simple pass through - the underlying docker-py Container.exec_run() also does not expose a timeout parameter. So this would need a client-side implementation, for example wrapping the call with concurrent.futures.ThreadPoolExecutor and a deadline, or using exec_run(socket=True) with a socket-level timeout.

Just like the timeout for a subprocess.run run doesn't guarantee closing the process after the timeout, so will this.

I'm happy to open a PR for this, but wanted to gain agreement on the issue first before submitting code.

Vorherrschende Sprache
Python
Sterne
2.3k
Forks
390
Ø Merge
11 T. 16 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus testcontainers/testcontainers-python

Alle Issues in testcontainers/testcontainers-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.