signal.raise_signal() and os.kill() now call PyErr_CheckSignals() to
check immediately for pending signals.
--- /dev/null
+:func:`signal.raise_signal` and :func:`os.kill` now check immediately for
+pending signals. Patch by Victor Stinner.
return NULL;
}
#ifndef MS_WINDOWS
- if (kill(pid, (int)signal) == -1)
+ if (kill(pid, (int)signal) == -1) {
return posix_error();
+ }
+
+ // Check immediately if the signal was sent to the current process.
+ // Don't micro-optimize pid == getpid(), since PyErr_SetString() check
+ // is cheap.
+ if (PyErr_CheckSignals()) {
+ return NULL;
+ }
+
Py_RETURN_NONE;
#else /* !MS_WINDOWS */
PyObject *result;
if (err) {
return PyErr_SetFromErrno(PyExc_OSError);
}
+
+ // If the current thread can handle signals, handle immediately
+ // the raised signal.
+ if (PyErr_CheckSignals()) {
+ return NULL;
+ }
+
Py_RETURN_NONE;
}