diff -r ff95708d4427 Modules/_tkinter.c --- a/Modules/_tkinter.c Tue Jun 02 11:38:01 2015 -0400 +++ b/Modules/_tkinter.c Thu Jun 04 21:29:32 2015 +0900 @@ -24,6 +24,7 @@ #include "Python.h" #include +#include #ifdef WITH_THREAD #include "pythread.h" @@ -3527,12 +3528,29 @@ static PyThreadState *event_tstate = NULL; #endif +static Tcl_AsyncHandler handler; + +static void sigint_handler(int signum) +{ + Tcl_AsyncMark(handler); +} + +static int +interrupt_handler(ClientData clientData, Tcl_Interp *interp, int code) +{ + int* flag = (int*)clientData; + *flag = 1; + return code; +} + static int EventHook(void) { #ifndef MS_WINDOWS int tfile; #endif + int interrupted = 0; + PyOS_sighandler_t py_sigint_handler; #ifdef WITH_THREAD PyEval_RestoreThread(event_tstate); #endif @@ -3542,6 +3560,8 @@ tfile = fileno(stdin); Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL); #endif + py_sigint_handler = PyOS_setsig(SIGINT, sigint_handler); + handler = Tcl_AsyncCreate(interrupt_handler, (ClientData)&interrupted); while (!errorInCmd && !stdin_ready) { int result; #ifdef MS_WINDOWS @@ -3565,10 +3585,13 @@ #else result = Tcl_DoOneEvent(0); #endif + if (interrupted) break; if (result < 0) break; } + PyOS_setsig(SIGINT, py_sigint_handler); + Tcl_AsyncDelete(handler); #ifndef MS_WINDOWS Tcl_DeleteFileHandler(tfile); #endif @@ -3581,6 +3604,11 @@ #ifdef WITH_THREAD PyEval_SaveThread(); #endif + if (interrupted) { + raise(SIGINT); + errno = EINTR; + return -1; + } return 0; }