-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. #7911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Modules/_io/winconsoleio.c
Outdated
SetLastError(0); | ||
BOOL res = ReadConsoleW(handle, &buf[off], len, &n, NULL); | ||
|
||
if (!res) { | ||
err = GetLastError(); | ||
break; | ||
} | ||
if (n == (DWORD) - 1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) { | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. @zooba, does this need a test? It's an uncommon edge case that I discovered randomly while experimenting with CancelSynchronousIo
.
@ValeriyaSinevich, FYI read_console_w
and _PyOS_WindowsConsoleReadline
are still broken per bpo-28166 when PyErr_CheckSignals
returns 0, i.e. if it's not the main thread or the SIGINT handler doesn't raise. It's an easy fix in the same functions if you want to work on it. Just immediately continue
to retry ReadConsoleW
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs a test - it's a narrow enough fix that we're very unlikely to regress it.
Modules/_io/winconsoleio.c
Outdated
@@ -556,14 +556,18 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) { | |||
Py_BEGIN_ALLOW_THREADS | |||
DWORD off = 0; | |||
while (off < maxlen) { | |||
DWORD n, len = min(maxlen - off, BUFSIZ); | |||
DWORD n = (DWORD) - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a style nit, but the spaces around the -
here (and elsewhere) makes all of these much harder to read - they look like subtractions, rather than a cast. Please write them as (DWORD)-1
Thanks! |
Thanks @ValeriyaSinevich for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
Sorry @ValeriyaSinevich and @zooba, I had trouble checking out the |
GH-8342 is a backport of this pull request to the 3.7 branch. |
…nousIo. (pythonGH-7911) (cherry picked from commit ce75df3) Co-authored-by: ValeriyaSinevich <[email protected]>
GH-8343 is a backport of this pull request to the 3.6 branch. |
…nousIo. (GH-7911) (cherry picked from commit ce75df3) Co-authored-by: ValeriyaSinevich <[email protected]>
…nousIo. (GH-7911) Co-authored-by: ValeriyaSinevich <[email protected]>
Output error when ReadConsole is canceled by CancelSynchronousIo instead of crashing.
https://bugs.python.org/issue30237