Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`signal.raise_signal` and :func:`os.kill` now check immediately for
pending signals. Patch by Victor Stinner.
11 changes: 10 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7927,8 +7927,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;
Expand Down
7 changes: 7 additions & 0 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down