You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Docs: problem with page "msvcrt — Useful routines from the MS VC runtime" #159072
The page at https://docs.python.org/3/library/msvcrt.html has a problem:
For msvcrt.getch(), the last line reads: "The Control-C keypress cannot be read with this function."
Current behavior in Terminal: Ctrl-C is returned as b'\x03' when pressed while getch() is waiting
Ordinary letter keys are also returned as expected, such as b'd' and b'c'.
This contradicts the documentation statement that the Control-C keypress cannot be read with this function. I would like to work on a documentation fix.
Yes, Ctrl+C does work in Python on Windows, although reading it as a character and triggering an interrupt are different behaviors.
In my manual test on Windows 10.0.26200.9457 with CPython 3.14.7, pressing Ctrl+C while msvcrt.getch() was waiting returned b'\x03' without raising KeyboardInterrupt.
I think this is what the docs meant here. So they should be corrected accordingly to that I think. What about signal handlers? (does it even work on Windows?)
Thanks for pointing out that distinction. I tested this with a custom handler registered using signal.signal(signal.SIGINT, handler) on Windows 10.0.26200.9457 with CPython 3.14.7.
Pressing Ctrl+C while msvcrt.getch() was waiting returned b'\x03', and the handler was not called. As a comparison, pressing Ctrl+C while input() was waiting called the handler with SIGINT (2), after which input() raised EOFError.
So SIGINT handlers do work on Windows in this test. I agree that the documentation should distinguish reading the Ctrl+C character from triggering interrupt handling.
Activity
jikekei commentedon Oct 10, 2026
I can reproduce this in a Windows console.
Environment:
Reproducer:
Pressing Ctrl+C while
getch()is waiting returns:Ordinary letter keys are also returned as expected, such as
b'd'andb'c'.This contradicts the documentation statement that the Control-C keypress cannot be read with this function. I would like to work on a documentation fix.
picnixz commentedon Oct 10, 2026
I think the docs mean that Ctrl+C is not sending SIGINT to the terminal, not that it is not read.
picnixz commentedon Oct 10, 2026
Wait if it is Windows, does Ctrl+C even work?
jikekei commentedon Oct 10, 2026
Yes, Ctrl+C does work in Python on Windows, although reading it as a character and triggering an interrupt are different behaviors.
In my manual test on Windows 10.0.26200.9457 with CPython 3.14.7, pressing Ctrl+C while msvcrt.getch() was waiting returned b'\x03' without raising KeyboardInterrupt.
picnixz commentedon Oct 10, 2026
I think this is what the docs meant here. So they should be corrected accordingly to that I think. What about signal handlers? (does it even work on Windows?)
jikekei commentedon Oct 10, 2026
Thanks for pointing out that distinction. I tested this with a custom handler registered using signal.signal(signal.SIGINT, handler) on Windows 10.0.26200.9457 with CPython 3.14.7.
Pressing Ctrl+C while msvcrt.getch() was waiting returned b'\x03', and the handler was not called. As a comparison, pressing Ctrl+C while input() was waiting called the handler with SIGINT (2), after which input() raised EOFError.
So SIGINT handlers do work on Windows in this test. I agree that the documentation should distinguish reading the Ctrl+C character from triggering interrupt handling.
pythongh-159072: Clarify Ctrl+C and SIGINT handler behavior