]> granicus.if.org Git - python/commitdiff
(Merge 3.1) Issue #11768: The signal handler of the signal module only calls
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 18 Apr 2011 14:33:28 +0000 (16:33 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 18 Apr 2011 14:33:28 +0000 (16:33 +0200)
Py_AddPendingCall() for the first signal to fix a deadlock on reentrant or
parallel calls. PyErr_SetInterrupt() writes also into the wake up file.

Misc/NEWS
Modules/signalmodule.c

index 738139709ada914c90dfdfae4aae0cfe5b58020f..ad532abda96d5fd6175b33f0bb717f3f1916f9f9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -55,6 +55,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #11768: The signal handler of the signal module only calls
+  Py_AddPendingCall() for the first signal to fix a deadlock on reentrant or
+  parallel calls. PyErr_SetInterrupt() writes also into the wake up file.
+
 - Issue #11442: Add a charset parameter to the Content-type in SimpleHTTPServer
   to avoid XSS attacks.
 
index 24410996eeb5db3fe54d69b719cf58e6bb845062..f306bba16f53965aede614bdbc3c57c93f09c1ca 100644 (file)
@@ -166,6 +166,20 @@ checksignals_witharg(void * unused)
     return PyErr_CheckSignals();
 }
 
+static void
+trip_signal(int sig_num)
+{
+    Handlers[sig_num].tripped = 1;
+    if (is_tripped)
+        return;
+    /* Set is_tripped after setting .tripped, as it gets
+       cleared in PyErr_CheckSignals() before .tripped. */
+    is_tripped = 1;
+    Py_AddPendingCall(checksignals_witharg, NULL);
+    if (wakeup_fd != -1)
+        write(wakeup_fd, "\0", 1);
+}
+
 static void
 signal_handler(int sig_num)
 {
@@ -183,13 +197,7 @@ signal_handler(int sig_num)
     if (getpid() == main_pid)
 #endif
     {
-        Handlers[sig_num].tripped = 1;
-        /* Set is_tripped after setting .tripped, as it gets
-           cleared in PyErr_CheckSignals() before .tripped. */
-        is_tripped = 1;
-        Py_AddPendingCall(checksignals_witharg, NULL);
-        if (wakeup_fd != -1)
-            write(wakeup_fd, "\0", 1);
+        trip_signal(sig_num);
     }
 
 #ifndef HAVE_SIGACTION
@@ -934,9 +942,7 @@ PyErr_CheckSignals(void)
 void
 PyErr_SetInterrupt(void)
 {
-    is_tripped = 1;
-    Handlers[SIGINT].tripped = 1;
-    Py_AddPendingCall((int (*)(void *))PyErr_CheckSignals, NULL);
+    trip_signal(SIGINT);
 }
 
 void