gh-72353: Continue reading from the console after ignored Ctrl+C - #155434
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-72353: Continue reading from the console after ignored Ctrl+C#155434serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
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>
serhiy-storchaka
requested review from
lysnikolaou and
pablogsal
as code owners
August 9, 2026 13:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #17976 and #8344, which made the same change but treated
WAIT_TIMEOUTas if the event had been signalled -- resetting an event that was never given to us and checking signals for nothing -- and leftWAIT_FAILEDignored. 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 withWriteConsoleInputW()make the console cancel a pending read; only a real keypress does. Verified by hand on Windows 11 withsignal.signal(signal.SIGINT, signal.SIG_IGN): typingabc, Ctrl+C,defraisedEOFErrorbefore this change and returns'def'after it.