subprocess.run timeout does not function if shell=True and capture_output=True
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
I am using python 3.12.4 on windows 10 and when calling subprocess.run("powershell", shell=True, capture_output=True, timeout=1) code execution seems to suspend indefinetly as the process now accepts the user input and interprets it.
This behaviour matches the one described in #81605 despite it having supposedly been fixed 5 years ago.
For example when calling subprocess.run("cmd", shell=True, capture_output=True, timeout=1) and then entering echo o>f.txt a new file called "f.txt" gets created with "o" as its content.
When using the IDLE Shell the process completes nearly instandly and returns this:
CompletedProcess(args='powershell', returncode=0, stdout=b'Windows PowerShell\r\nCopyright (C) Microsoft Corporation. Alle Rechte vorbehalten.\r\n\r\nLernen Sie das neue plattform\x81bergreifende PowerShell kennen - https://aka.ms/pscore6\r\n\r\nPS C:\Users\Mabeeck\Desktop\Python> ', stderr=b'')
The same applies for Python 3.8.9, 3.9.2, 3.10.6, 3.11.5 and 3.13.0b3
I'll apoligise in advance, if my impression of the bug beeing supposed to be fixed is wrong.
CPython versions tested on:
3.8, 3.9, 3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Windows
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với entry point subprocess.run bằng cách sử dụng shell=True, capture_output=True và timeout=1 trên Windows, tái hiện các trường hợp powershell và cmd đã được báo cáo. So sánh hành vi giữa các phiên bản Python được liệt kê và xác định hành vi timeout nào sẽ xảy ra khi tiến trình con chấp nhận đầu vào; issue hoàn tất khi tình trạng treo vô thời hạn được giải quyết và hành vi được bao phủ bởi một regression test phù hợp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- powershell, python, shell
- Lĩnh vực
- operating-systems
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100