bpo-37951: Lift subprocess's fork() restriction (GH-15544)
(cherry picked from commit 98d90f745d35d5d07bffcb46788b50e05eea56c6)
Co-authored-by: Christian Heimes <christian@python.org>
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index 81a23c6..e693e53 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -583,8 +583,10 @@
&restore_signals, &call_setsid, &preexec_fn))
return NULL;
- if (_PyInterpreterState_Get() != PyInterpreterState_Main()) {
- PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
+ if ((preexec_fn != Py_None) &&
+ (_PyInterpreterState_Get() != PyInterpreterState_Main())) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "preexec_fn not supported within subinterpreters");
return NULL;
}