Misbehavior of KeyboardInterrupt/EOFError and `input` on Windows
未關閉
還沒有人認領這個 Issue。
OS-windows
pending
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
import sys
from http.server import BaseHTTPRequestHandler, HTTPServer
from typing import NoReturn
def run_server() -> None:
httpd = HTTPServer(("", 0), BaseHTTPRequestHandler)
print("Starting service")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("Service stopped by ^C")
finally:
httpd.shutdown()
httpd.server_close()
def run() -> NoReturn:
print(f"Python: v{sys.version}")
while True:
try:
input("input>")
except KeyboardInterrupt:
print("^C")
continue
except EOFError:
print("Manually force exit")
sys.exit()
run_server()
if __name__ == "__main__":
run()
I'm not sure if it's a bug
Expected
- When
input,^Ccan cancel current input and enter the next cycle - When
server,^Ccan close server and enter the next cycle ^Zto exit (print("Manually force exit"))
Factual
Enterto open server -> type^Cto close server -> type^C- When
py xxx.py,print("Manually force exit") - When
pdb,\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_sys_monitoring\_pydevd_sys_monitoring.py", line 873 KeyboardInterrupt
- When
CPython versions tested on:
3.14
Operating systems tested on:
Windows
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先,在 Windows 上使用 Python 3.14 重現所提供的 run() 範例,重點關注 input、KeyboardInterrupt、EOFError 以及向 run_server 的轉換。比較正常啟動和在 pdb 下啟動時的行為;當觀察到的控制流程符合關於取消輸入、停止伺服器以及使用 ^Z 結束的預期時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- cli, operating-systems
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 35/100