python / python/cpython

Misbehavior of KeyboardInterrupt/EOFError and `input` on Windows

Aperta
#141,381 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

OS-windows pending stdlib type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo l'esempio run() fornito su Windows con Python 3.14, concentrandoti su input, KeyboardInterrupt, EOFError e sulla transizione di run_server. Confronta il comportamento quando viene avviato normalmente e sotto pdb; il lavoro è completato quando il flusso di controllo osservato corrisponde alle aspettative indicate per l'annullamento dell'input, l'arresto del server e l'uscita con ^Z.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
cli, operating-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.