testcontainers / testcontainers/testcontainers-python
Feature: Timeout on command execution
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 2.3k
- フォーク
- 386
- 平均マージ
- 4時間 40分
- マージ済み PR(30日)
- 1
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
DockerContainer.exec と docs/features/executing_commands.md から始め、ドキュメントに記載された timeout の例を docker-py Container.exec_run およびその制限事項と比較します。exec() が timeout を受け付け、期限を超過したときに TimeoutError を発生させ、test run を無期限にブロックしたままにしなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- docker, python
- 領域
- devops, testing
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100