summaryrefslogtreecommitdiffstats
path: root/Parser/myreadline.c
diff options
context:
space:
mode:
Diffstat (limited to 'Parser/myreadline.c')
-rw-r--r--Parser/myreadline.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index 93edd7f..d864623 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -35,12 +35,11 @@ int (*PyOS_InputHook)(void) = NULL;
static int
my_fgets(char *buf, int len, FILE *fp)
{
- char *p;
- int err;
#ifdef MS_WINDOWS
- int i;
+ HANDLE hInterruptEvent;
#endif
-
+ char *p;
+ int err;
while (1) {
if (PyOS_InputHook != NULL)
(void)(PyOS_InputHook)();
@@ -57,20 +56,24 @@ my_fgets(char *buf, int len, FILE *fp)
/* Ctrl-C anywhere on the line or Ctrl-Z if the only character
on a line will set ERROR_OPERATION_ABORTED. Under normal
circumstances Ctrl-C will also have caused the SIGINT handler
- to fire. This signal fires in another thread and is not
- guaranteed to have occurred before this point in the code.
-
- Therefore: check in a small loop to see if the trigger has
- fired, in which case assume this is a Ctrl-C event. If it
- hasn't fired within 10ms assume that this is a Ctrl-Z on its
- own or that the signal isn't going to fire for some other
- reason and drop through to check for EOF.
+ to fire which will have set the event object returned by
+ _PyOS_SigintEvent. This signal fires in another thread and
+ is not guaranteed to have occurred before this point in the
+ code.
+
+ Therefore: check whether the event is set with a small timeout.
+ If it is, assume this is a Ctrl-C and reset the event. If it
+ isn't set assume that this is a Ctrl-Z on its own and drop
+ through to check for EOF.
*/
if (GetLastError()==ERROR_OPERATION_ABORTED) {
- for (i = 0; i < 10; i++) {
- if (PyOS_InterruptOccurred())
- return 1;
- Sleep(1);
+ hInterruptEvent = _PyOS_SigintEvent();
+ switch (WaitForSingleObject(hInterruptEvent, 10)) {
+ case WAIT_OBJECT_0:
+ ResetEvent(hInterruptEvent);
+ return 1; /* Interrupt */
+ case WAIT_FAILED:
+ return -2; /* Error */
}
}
#endif /* MS_WINDOWS */
@@ -90,7 +93,7 @@ my_fgets(char *buf, int len, FILE *fp)
#endif
if (s < 0)
return 1;
- /* try again */
+ /* try again */
continue;
}
#endif