python / python/cpython

subprocess.run keeps waiting after the process termination

オープン
#97,000 コメント 4 件 リアクション 0 件 担当者 1 名 GitHub で見る

@gpshead がすでに取り組んでいます。

2022年10月23日 から。

stdlib topic-subprocess type-bug
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

説明

subprocess.run keeps waiting after the process termination.
This happens when stdout or stderr is redirected, and the started process pass that stream to a background process.

Reproduce with:

import subprocess
subprocess.run(["/bin/bash", "-c", "sleep 5&"], stdout=subprocess.PIPE, timeout=1)

Result:
subprocess.TimeoutExpired: Command '['/bin/bash', '-c', 'sleep 5&']' timed out after 1 seconds
This is not correct as the subprocess has terminated and produces a return code.
The expected behavior for run is to return as soon as the instanciated terminates, regardless of the streams lifecycles.

Variants:
Calling subprocess.run(["/bin/bash", "-c", "sleep 5&"], timeout=1) works as expected, that is to say run returns immediately.

Environment:

Python 3.8.9:

  • CPython versions tested on:
  • Operating system MacOs, Linux

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。