python / python/cpython

Misbehavior of KeyboardInterrupt/EOFError and `input` on Windows

Open
#141,381 7 comments 0 reactions 0 assignees View on GitHub

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, ^C can cancel current input and enter the next cycle
  • When server, ^C can close server and enter the next cycle
  • ^Z to exit (print("Manually force exit"))
Factual
  • Enter to open server -> type ^C to 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
CPython versions tested on:

3.14

Operating systems tested on:

Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.