Skip to content

gh-72353: Continue reading from the console after ignored Ctrl+C - #155434

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-72353-console-ctrl-c
Open

gh-72353: Continue reading from the console after ignored Ctrl+C#155434
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-72353-console-ctrl-c

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 9, 2026

Copy link
Copy Markdown
Member

Supersedes #17976 and #8344, which made the same change but treated WAIT_TIMEOUT as if the event had been signalled -- resetting an event that was never given to us and checking signals for nothing -- and left WAIT_FAILED ignored. Here the timeout only restarts the read, and a failed wait is reported.

Input typed before the Ctrl+C is still lost: the console host cancels the read and flushes its input buffer before Python sees the interrupt. Restarting the read is nevertheless better than ending it as if at end of file.

This cannot be tested automatically -- neither GenerateConsoleCtrlEvent() nor key records written with WriteConsoleInputW() make the console cancel a pending read; only a real keypress does. Verified by hand on Windows 11 with signal.signal(signal.SIGINT, signal.SIG_IGN): typing abc, Ctrl+C, def raised EOFError before this change and returns 'def' after it.

If the console cancels a read because of Ctrl+C, but the SIGINT handler
does not raise an exception, restart the read instead of ending it as if
at end of file.

Co-authored-by: Valeriya Sinevich <valeriya.sinevich@phystech.edu>
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant