Misbehavior of KeyboardInterrupt/EOFError and `input` on Windows
未关闭
还没有人认领这个 Issue。
OS-windows
pending
stdlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- 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