Skip to content

Misbehavior of KeyboardInterrupt/EOFError and input on Windows #141381

@op200

Description

@op200

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowspendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions