Misbehavior of KeyboardInterrupt/EOFError and `input` on Windows
Open
Nobody has claimed this yet.
OS-windows
pending
stdlib
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied run() example on Windows with Python 3.14, focusing on input, KeyboardInterrupt, EOFError, and the run_server transition. Compare behavior when launched normally and under pdb; done means the observed control flow matches the stated expectations for cancelling input, stopping the server, and exiting with ^Z.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100