Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Reading from the console on Windows now continues if the read was cancelled
by Ctrl+C, but the :const:`~signal.SIGINT` handler did not raise an
exception. Previously the read ended as if at end of file.
11 changes: 9 additions & 2 deletions Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,15 +644,22 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
break;
err = 0;
HANDLE hInterruptEvent = _PyOS_SigintEvent();
if (WaitForSingleObjectEx(hInterruptEvent, 100, FALSE)
== WAIT_OBJECT_0) {
DWORD state = WaitForSingleObjectEx(hInterruptEvent, 100, FALSE);
if (state == WAIT_OBJECT_0) {
ResetEvent(hInterruptEvent);
Py_BLOCK_THREADS
sig = PyErr_CheckSignals();
Py_UNBLOCK_THREADS
if (sig < 0)
break;
}
else if (state != WAIT_TIMEOUT) {
err = GetLastError();
break;
}
/* The console cancelled the read and flushed its input buffer,
but no exception was raised. Start the read over. */
continue;
}
*readlen += n;

Expand Down
12 changes: 9 additions & 3 deletions Parser/myreadline.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ _PyOS_WindowsConsoleReadline(PyThreadState *tstate, HANDLE hStdIn)
goto exit;
err = 0;
HANDLE hInterruptEvent = _PyOS_SigintEvent();
if (WaitForSingleObjectEx(hInterruptEvent, 100, FALSE)
== WAIT_OBJECT_0) {
DWORD state = WaitForSingleObjectEx(hInterruptEvent, 100, FALSE);
if (state == WAIT_OBJECT_0) {
ResetEvent(hInterruptEvent);
PyEval_RestoreThread(tstate);
s = PyErr_CheckSignals();
Expand All @@ -172,7 +172,13 @@ _PyOS_WindowsConsoleReadline(PyThreadState *tstate, HANDLE hStdIn)
goto exit;
}
}
break;
else if (state != WAIT_TIMEOUT) {
err = GetLastError();
goto exit;
}
/* The console cancelled the read and flushed its input buffer,
but no exception was raised. Start the read over. */
continue;
}

total_read += n_read;
Expand Down
Loading