Skip to content

Docs: problem with page "msvcrt — Useful routines from the MS VC runtime" #159072

Description

@MHolender

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

Linked PRs

Activity

  1. jikekei commented on Oct 10, 2026

    @jikekei

    I can reproduce this in a Windows console.

    Environment:

    • Windows version: 10.0.26200.9457
    • CPython 3.14.7, 64-bit (AMD64), MSC v.1944

    Reproducer:

    import msvcrt
    import sys
    
    print(sys.version)
    print("Received:", repr(msvcrt.getch()))

    Pressing Ctrl+C while getch() is waiting returns:

    Received: b'\x03'
    

    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.

  2. picnixz commented on Oct 10, 2026

    @picnixz
    Member

    I think the docs mean that Ctrl+C is not sending SIGINT to the terminal, not that it is not read.

  3. picnixz commented on Oct 10, 2026

    @picnixz
    Member

    Wait if it is Windows, does Ctrl+C even work?

  4. jikekei commented on Oct 10, 2026

    @jikekei

    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.

  5. picnixz commented on Oct 10, 2026

    @picnixz
    Member

    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?)

  6. jikekei commented on Oct 10, 2026

    @jikekei

    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.

  7. added a commit that references this issue on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions