python / python/cpython

subprocess.run timeout does not function if shell=True and capture_output=True

未關閉
#121,157 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-subprocess type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Windows 上使用 shell=True、capture_output=True 和 timeout=1 的 subprocess.run 入口點開始,重現回報的 powershell 和 cmd 情況。比較所列 Python 版本之間的行為,並確定子程序接受輸入時應發生什麼 timeout 行為;當無限期暫停問題獲得解決,且該行為由適當的回歸測試涵蓋時,issue 即完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
powershell, python, shell
領域
operating-systems
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
需要釐清
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。