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 @@
Importing the :mod:`_signal` module in a subinterpreter has no longer side
effects.
68 changes: 41 additions & 27 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1544,33 +1544,8 @@ signal_add_constants(PyObject *module)


static int
signal_module_exec(PyObject *m)
signal_get_set_handlers(PyObject *mod_dict)
{
assert(!PyErr_Occurred());

if (signal_add_constants(m) < 0) {
return -1;
}

/* Add some symbolic constants to the module */
PyObject *d = PyModule_GetDict(m);
if (PyDict_SetItemString(d, "SIG_DFL", DefaultHandler) < 0) {
return -1;
}
if (PyDict_SetItemString(d, "SIG_IGN", IgnoreHandler) < 0) {
return -1;
}
#if defined(HAVE_GETITIMER) || defined(HAVE_SETITIMER)
if (PyDict_SetItemString(d, "ItimerError", ItimerError) < 0) {
return -1;
}
#endif
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
if (PyModule_AddType(m, &SiginfoType) < 0) {
return -1;
}
#endif

// Get signal handlers
for (int signum = 1; signum < NSIG; signum++) {
void (*c_handler)(int) = PyOS_getsig(signum);
Expand All @@ -1594,7 +1569,8 @@ signal_module_exec(PyObject *m)
// Instal Python SIGINT handler which raises KeyboardInterrupt
PyObject* sigint_func = get_handler(SIGINT);
if (sigint_func == DefaultHandler) {
PyObject *int_handler = PyMapping_GetItemString(d, "default_int_handler");
PyObject *int_handler = PyMapping_GetItemString(mod_dict,
"default_int_handler");
if (!int_handler) {
return -1;
}
Expand All @@ -1603,6 +1579,44 @@ signal_module_exec(PyObject *m)
Py_DECREF(sigint_func);
PyOS_setsig(SIGINT, signal_handler);
}
return 0;
}


static int
signal_module_exec(PyObject *m)
{
assert(!PyErr_Occurred());

if (signal_add_constants(m) < 0) {
return -1;
}

/* Add some symbolic constants to the module */
PyObject *d = PyModule_GetDict(m);
if (PyDict_SetItemString(d, "SIG_DFL", DefaultHandler) < 0) {
return -1;
}
if (PyDict_SetItemString(d, "SIG_IGN", IgnoreHandler) < 0) {
return -1;
}
#if defined(HAVE_GETITIMER) || defined(HAVE_SETITIMER)
if (PyDict_SetItemString(d, "ItimerError", ItimerError) < 0) {
return -1;
}
#endif
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
if (PyModule_AddType(m, &SiginfoType) < 0) {
return -1;
}
#endif

PyThreadState *tstate = _PyThreadState_GET();
if (_Py_IsMainInterpreter(tstate->interp)) {
if (signal_get_set_handlers(d) < 0) {
return -1;
}
}

assert(!PyErr_Occurred());
return 0;
Expand Down