summaryrefslogtreecommitdiff
path: root/Modules/signalmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-21 21:26:56 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-21 21:26:56 +0100
commit6aa9b246c7e6a5c63e62e8e0f05b14c1694644cc (patch)
tree38cac0a827c1d03ea7edd8b6091e2efe113a9b9f /Modules/signalmodule.c
parent3760c4be4574f55fa15ce01443d780263f2d00e9 (diff)
downloadcpython-6aa9b246c7e6a5c63e62e8e0f05b14c1694644cc.tar.gz
Issue #12328: Under Windows, refactor handling of Ctrl-C events and
make _multiprocessing.win32.WaitForMultipleObjects interruptible when the wait_flag parameter is false. Patch by sbt.
Diffstat (limited to 'Modules/signalmodule.c')
-rw-r--r--Modules/signalmodule.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 45a7dfad3b..c28f7afab0 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -109,6 +109,10 @@ static PyObject *IntHandler;
static PyOS_sighandler_t old_siginthandler = SIG_DFL;
+#ifdef MS_WINDOWS
+static HANDLE sigint_event = NULL;
+#endif
+
#ifdef HAVE_GETITIMER
static PyObject *ItimerError;
@@ -229,6 +233,11 @@ signal_handler(int sig_num)
/* Issue #10311: asynchronously executing signal handlers should not
mutate errno under the feet of unsuspecting C code. */
errno = save_errno;
+
+#ifdef MS_WINDOWS
+ if (sig_num == SIGINT)
+ SetEvent(sigint_event);
+#endif
}
@@ -1253,6 +1262,11 @@ PyInit_signal(void)
Py_DECREF(x);
#endif
+#ifdef MS_WINDOWS
+ /* Create manual-reset event, initially unset */
+ sigint_event = CreateEvent(NULL, TRUE, FALSE, FALSE);
+#endif
+
if (PyErr_Occurred()) {
Py_DECREF(m);
m = NULL;
@@ -1397,3 +1411,25 @@ PyOS_AfterFork(void)
PyThread_ReInitTLS();
#endif
}
+
+int
+_PyOS_IsMainThread(void)
+{
+#ifdef WITH_THREAD
+ return PyThread_get_thread_ident() == main_thread;
+#else
+ return 1;
+#endif
+}
+
+#ifdef MS_WINDOWS
+void *_PyOS_SigintEvent(void)
+{
+ /* Returns a manual-reset event which gets tripped whenever
+ SIGINT is received.
+
+ Python.h does not include windows.h so we do cannot use HANDLE
+ as the return type of this function. We use void* instead. */
+ return sigint_event;
+}
+#endif