summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-04-18 14:28:39 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-04-18 14:28:39 (GMT)
commit27026f87d8aba31c3aa5529971508a91017486f5 (patch)
tree492f2b447afa0d9a9da792641460e91ea6a2991a
parent01581ee0b7c968adb987a36495af7ce5eb794d0d (diff)
parent6c9b35bfe2585af08ea6480294e096e2d2397fe3 (diff)
downloadcpython-27026f87d8aba31c3aa5529971508a91017486f5.zip
cpython-27026f87d8aba31c3aa5529971508a91017486f5.tar.gz
cpython-27026f87d8aba31c3aa5529971508a91017486f5.tar.bz2
(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.
-rw-r--r--Misc/NEWS4
-rw-r--r--Modules/signalmodule.c26
2 files changed, 20 insertions, 10 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index dda300f..a34f009 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,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 #11492: fix several issues with header folding in the email package.
- Issue #11852: Add missing imports and update tests.
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index a93caad..d34f132 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -166,6 +166,20 @@ checksignals_witharg(void * unused)
}
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;
@@ -182,13 +196,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
@@ -946,9 +954,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