python / python/cpython

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

Đang mở
#96,863 5 bình luận 0 reaction 2 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib topic-subprocess type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.