summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-04-21 01:14:57 (GMT)
committerGitHub <noreply@github.com>2022-04-21 01:14:57 (GMT)
commit031f1e6040d1bb0454bd6da417fd9e38aad4fc89 (patch)
treeccca4d8d9d29e30c7d40dac590974356df7f2d7a /Modules
parentc77953b23e4b864129edf7983eaa6a0d22414ec6 (diff)
downloadcpython-031f1e6040d1bb0454bd6da417fd9e38aad4fc89.zip
cpython-031f1e6040d1bb0454bd6da417fd9e38aad4fc89.tar.gz
cpython-031f1e6040d1bb0454bd6da417fd9e38aad4fc89.tar.bz2
gh-90623: signal.raise_signal() calls PyErr_CheckSignals() (#91756)
signal.raise_signal() and os.kill() now call PyErr_CheckSignals() to check immediately for pending signals.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c11
-rw-r--r--Modules/signalmodule.c7
2 files changed, 17 insertions, 1 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 345ed71..a9132a7 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7929,8 +7929,17 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
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;
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 1ee5c66..02c58ff 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -481,6 +481,13 @@ signal_raise_signal_impl(PyObject *module, int signalnum)
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;
}