Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c9b35b

Browse files
author
Victor Stinner
committed
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.
1 parent 340bb95 commit 6c9b35b

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Core and Builtins
5555
Library
5656
-------
5757

58+
- Issue #11768: The signal handler of the signal module only calls
59+
Py_AddPendingCall() for the first signal to fix a deadlock on reentrant or
60+
parallel calls. PyErr_SetInterrupt() writes also into the wake up file.
61+
5862
- Issue #11467: Fix urlparse behavior when handling urls which contains scheme
5963
specific part only digits. Patch by Santoso Wijaya.
6064

Modules/signalmodule.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ checksignals_witharg(void * unused)
163163
return PyErr_CheckSignals();
164164
}
165165

166+
static void
167+
trip_signal(int sig_num)
168+
{
169+
Handlers[sig_num].tripped = 1;
170+
if (is_tripped)
171+
return;
172+
/* Set is_tripped after setting .tripped, as it gets
173+
cleared in PyErr_CheckSignals() before .tripped. */
174+
is_tripped = 1;
175+
Py_AddPendingCall(checksignals_witharg, NULL);
176+
if (wakeup_fd != -1)
177+
write(wakeup_fd, "\0", 1);
178+
}
179+
166180
static void
167181
signal_handler(int sig_num)
168182
{
@@ -180,13 +194,7 @@ signal_handler(int sig_num)
180194
if (getpid() == main_pid)
181195
#endif
182196
{
183-
Handlers[sig_num].tripped = 1;
184-
/* Set is_tripped after setting .tripped, as it gets
185-
cleared in PyErr_CheckSignals() before .tripped. */
186-
is_tripped = 1;
187-
Py_AddPendingCall(checksignals_witharg, NULL);
188-
if (wakeup_fd != -1)
189-
write(wakeup_fd, "\0", 1);
197+
trip_signal(sig_num);
190198
}
191199

192200
#ifndef HAVE_SIGACTION
@@ -932,9 +940,7 @@ PyErr_CheckSignals(void)
932940
void
933941
PyErr_SetInterrupt(void)
934942
{
935-
is_tripped = 1;
936-
Handlers[SIGINT].tripped = 1;
937-
Py_AddPendingCall((int (*)(void *))PyErr_CheckSignals, NULL);
943+
trip_signal(SIGINT);
938944
}
939945

940946
void

0 commit comments

Comments
 (0)