| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0e8100a commit c922aa0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Reading from the console on Windows now continues if the read was cancelled | ||
| 2 | + by Ctrl+C, but the :const:`~signal.SIGINT` handler did not raise an | ||
| 3 | + exception. Previously the read ended as if at end of file. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -644,15 +644,22 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) { | |||
| 644 | 644 | break; | |
| 645 | 645 | err = 0; | |
| 646 | 646 | HANDLE hInterruptEvent = _PyOS_SigintEvent(); | |
| 647 | - if (WaitForSingleObjectEx(hInterruptEvent, 100, FALSE) | ||
| 648 | - == WAIT_OBJECT_0) { | ||
| 647 | + DWORD state = WaitForSingleObjectEx(hInterruptEvent, 100, FALSE); | ||
| 648 | + if (state == WAIT_OBJECT_0) { | ||
| 649 | 649 | ResetEvent(hInterruptEvent); | |
| 650 | 650 | Py_BLOCK_THREADS | |
| 651 | 651 | sig = PyErr_CheckSignals(); | |
| 652 | 652 | Py_UNBLOCK_THREADS | |
| 653 | 653 | if (sig < 0) | |
| 654 | 654 | break; | |
| 655 | 655 | } | |
| 656 | + else if (state != WAIT_TIMEOUT) { | ||
| 657 | + err = GetLastError(); | ||
| 658 | + break; | ||
| 659 | + } | ||
| 660 | + /* The console cancelled the read and flushed its input buffer, | ||
| 661 | + but no exception was raised. Start the read over. */ | ||
| 662 | + continue; | ||
| 656 | 663 | } | |
| 657 | 664 | *readlen += n; | |
| 658 | 665 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,8 +162,8 @@ _PyOS_WindowsConsoleReadline(PyThreadState *tstate, HANDLE hStdIn) | |||
| 162 | 162 | goto exit; | |
| 163 | 163 | err = 0; | |
| 164 | 164 | HANDLE hInterruptEvent = _PyOS_SigintEvent(); | |
| 165 | - if (WaitForSingleObjectEx(hInterruptEvent, 100, FALSE) | ||
| 166 | - == WAIT_OBJECT_0) { | ||
| 165 | + DWORD state = WaitForSingleObjectEx(hInterruptEvent, 100, FALSE); | ||
| 166 | + if (state == WAIT_OBJECT_0) { | ||
| 167 | 167 | ResetEvent(hInterruptEvent); | |
| 168 | 168 | PyEval_RestoreThread(tstate); | |
| 169 | 169 | s = PyErr_CheckSignals(); | |
@@ -172,7 +172,13 @@ _PyOS_WindowsConsoleReadline(PyThreadState *tstate, HANDLE hStdIn) | |||
| 172 | 172 | goto exit; | |
| 173 | 173 | } | |
| 174 | 174 | } | |
| 175 | - break; | ||
| 175 | + else if (state != WAIT_TIMEOUT) { | ||
| 176 | + err = GetLastError(); | ||
| 177 | + goto exit; | ||
| 178 | + } | ||
| 179 | + /* The console cancelled the read and flushed its input buffer, | ||
| 180 | + but no exception was raised. Start the read over. */ | ||
| 181 | + continue; | ||
| 176 | 182 | } | |
| 177 | 183 | ||
| 178 | 184 | total_read += n_read; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments