[Python-checkins] cpython (2.7): (Merge 3.1) Issue #11768: The signal handler of the signal module only calls

victor.stinner python-checkins at python.org
Mon Apr 18 16:34:33 CEST 2011


http://hg.python.org/cpython/rev/7d355c2ff3d4
changeset:   69426:7d355c2ff3d4
branch:      2.7
parent:      69417:fc2def15ab11
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Mon Apr 18 16:33:28 2011 +0200
summary:
  (Merge 3.1) 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.

files:
  Misc/NEWS              |   4 ++++
  Modules/signalmodule.c |  26 ++++++++++++++++----------
  2 files changed, 20 insertions(+), 10 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -55,6 +55,10 @@
 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.
 
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -167,6 +167,20 @@
 }
 
 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)
 {
     int save_errno = errno;
@@ -183,13 +197,7 @@
     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 @@
 void
 PyErr_SetInterrupt(void)
 {
-    is_tripped = 1;
-    Handlers[SIGINT].tripped = 1;
-    Py_AddPendingCall((int (*)(void *))PyErr_CheckSignals, NULL);
+    trip_signal(SIGINT);
 }
 
 void

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list