aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 1960c6377c2..6f01b70d528 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7620,7 +7620,13 @@ os_fork1_impl(PyObject *module)
{
pid_t pid;
- if (!_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (interp->finalizing) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "can't fork at interpreter shutdown");
+ return NULL;
+ }
+ if (!_Py_IsMainInterpreter(interp)) {
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
return NULL;
}
@@ -7656,6 +7662,11 @@ os_fork_impl(PyObject *module)
{
pid_t pid;
PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (interp->finalizing) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "can't fork at interpreter shutdown");
+ return NULL;
+ }
if (!_PyInterpreterState_HasFeature(interp, Py_RTFLAGS_FORK)) {
PyErr_SetString(PyExc_RuntimeError,
"fork not supported for isolated subinterpreters");
@@ -8327,7 +8338,13 @@ os_forkpty_impl(PyObject *module)
int master_fd = -1;
pid_t pid;
- if (!_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (interp->finalizing) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "can't fork at interpreter shutdown");
+ return NULL;
+ }
+ if (!_Py_IsMainInterpreter(interp)) {
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
return NULL;
}