aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2018-09-14 14:17:20 -0700
committerGitHub <noreply@github.com>2018-09-14 14:17:20 -0700
commit5903296045b586b9cd1fce0b1e02caf896028d1d (patch)
tree99e8900633096060e931980d52e063c044870d3c /Modules/_posixsubprocess.c
parentbpo-33649: Refresh Tasks and Futures pages (#9314) (diff)
downloadcpython-5903296045b586b9cd1fce0b1e02caf896028d1d.tar.gz
cpython-5903296045b586b9cd1fce0b1e02caf896028d1d.tar.bz2
cpython-5903296045b586b9cd1fce0b1e02caf896028d1d.zip
bpo-34651: Only allow the main interpreter to fork. (gh-9279)
When os.fork() is called (on platforms that support it) all threads but the current one are destroyed in the child process. Consequently we must ensure that all but the associated interpreter are likewise destroyed. The main interpreter is critical for runtime operation, so we must ensure that fork only happens in the main interpreter. https://bugs.python.org/issue34651
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r--Modules/_posixsubprocess.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index dd69b9eb1ff..9661e38540e 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -576,6 +576,11 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
&restore_signals, &call_setsid, &preexec_fn))
return NULL;
+ if (_PyInterpreterState_Get() != PyInterpreterState_Main()) {
+ PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
+ return NULL;
+ }
+
if (close_fds && errpipe_write < 3) { /* precondition */
PyErr_SetString(PyExc_ValueError, "errpipe_write must be >= 3");
return NULL;