Incorrect exit status of an already waited process in subprocess.Popen

オープン
#96,863 コメント 5 件 リアクション 0 件 担当者 2 名 GitHub で見る

まだ誰も着手していません。

評価

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

説明

stdlib topic-subprocess type-bug

Bug report

If a process run by subprocess.Popen and its exit status is obtained by os.wait() or os.waitpid(), then calling the wait() method on the Popen object always returns zero.

Example:

import os
import subprocess

proc = subprocess.Popen(["false"]) # could be any process with non-zero exit status
pid, status = os.wait()
print("status from os.wait()", status)  # prints non-zero exit status correctly
print("status from proc.wait()", proc.wait()) # prints zero exit status incorrectly

The root cause of the problem is that the child has been already wait()ed, so the Popen object has no chance to obtain the exit code as the process no longer exists. It calls waitpid() here but it ignores ECHILD and defaults the status to zero.

Your environment

  • CPython versions tested on: Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
  • Operating system and architecture: Linux x86-64
Linked PRs
  • gh-137804
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

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

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

はじめの一歩

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

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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