diff -r ff95708d4427 Modules/readline.c --- a/Modules/readline.c Tue Jun 02 11:38:01 2015 -0400 +++ b/Modules/readline.c Wed Jun 03 23:13:05 2015 +0900 @@ -994,19 +994,22 @@ while (completed_input_string == not_done_reading) { int has_input = 0; - while (!has_input) - { struct timeval timeout = {0, 100000}; /* 0.1 seconds */ - + while (!has_input) { + struct timeval timeout = {0, 100000}; /* 0.1 seconds */ /* [Bug #1552726] Only limit the pause if an input hook has been defined. */ struct timeval *timeoutp = NULL; - if (PyOS_InputHook) + if (PyOS_InputHook) { timeoutp = &timeout; + if(PyOS_InputHook) { + has_input = PyOS_InputHook(); + if (has_input < 0) break; + } + } FD_SET(fileno(rl_instream), &selectset); /* select resets selectset if no input was available */ has_input = select(fileno(rl_instream) + 1, &selectset, NULL, NULL, timeoutp); - if(PyOS_InputHook) PyOS_InputHook(); } if(has_input > 0) { diff -r ff95708d4427 Parser/myreadline.c --- a/Parser/myreadline.c Tue Jun 02 11:38:01 2015 -0400 +++ b/Parser/myreadline.c Wed Jun 03 23:13:05 2015 +0900 @@ -45,37 +45,41 @@ #endif while (1) { - if (PyOS_InputHook != NULL) - (void)(PyOS_InputHook)(); - errno = 0; - clearerr(fp); - p = fgets(buf, len, fp); - if (p != NULL) - return 0; /* No error */ + int has_input = 0; + if (PyOS_InputHook != NULL) { + has_input = PyOS_InputHook(); + } + if (has_input >= 0) { + errno = 0; + clearerr(fp); + p = fgets(buf, len, fp); + if (p != NULL) + return 0; /* No error */ #ifdef MS_WINDOWS - /* 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. + /* 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. - */ - if (GetLastError()==ERROR_OPERATION_ABORTED) { - for (i = 0; i < 10; i++) { - if (PyOS_InterruptOccurred()) - return 1; - Sleep(1); + 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. + */ + if (GetLastError()==ERROR_OPERATION_ABORTED) { + for (i = 0; i < 10; i++) { + if (PyOS_InterruptOccurred()) + return 1; + Sleep(1); + } } - } #endif /* MS_WINDOWS */ - if (feof(fp)) { - clearerr(fp); - return -1; /* EOF */ + if (feof(fp)) { + clearerr(fp); + return -1; /* EOF */ + } } #ifdef EINTR if (errno == EINTR) {