python / python/cpython

subprocess.run keeps waiting after the process termination

Đang mở
#97,000 4 bình luận 0 reaction 1 người được giao Xem trên GitHub

@gpshead đang làm issue này rồi.

Từ ngày 23/10/2022.

stdlib topic-subprocess type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

Mô tả

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

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.