Skip to content

Commit

Permalink
bpo-37951: Lift subprocess's fork() restriction (pythonGH-15544)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiran authored Aug 27, 2019
1 parent 3224e1a commit 98d90f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Doc/library/subprocess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ functions.
The *start_new_session* parameter can take the place of a previously
common use of *preexec_fn* to call os.setsid() in the child.

.. versionchanged:: 3.8

The *preexec_fn* parameter is no longer supported in subinterpreters.
The use of the parameter in a subinterpreter raises
:exc:`RuntimeError`. The new restriction may affect applications that
are deployed in mod_wsgi, uWSGI, and other embedded environments.

If *close_fds* is true, all file descriptors except :const:`0`, :const:`1` and
:const:`2` will be closed before the child process is executed. Otherwise
when *close_fds* is false, file descriptors obey their inheritable flag
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,12 @@ Changes in the Python API
non-zero :attr:`~Popen.returncode`.
(Contributed by Joannah Nanjekye and Victor Stinner in :issue:`35537`.)

* The *preexec_fn* argument of * :class:`subprocess.Popen` is no longer
compatible with subinterpreters. The use of the parameter in a
subinterpreter now raises :exc:`RuntimeError`.
(Contributed by Eric Snow in :issue:`34651`, modified by Christian Heimes
in :issue:`37951`.)

* The :meth:`imap.IMAP4.logout` method no longer ignores silently arbitrary
exceptions.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Most features of the subprocess module now work again in subinterpreters.
Only *preexec_fn* is restricted in subinterpreters.
6 changes: 4 additions & 2 deletions Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,10 @@ 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");
if ((preexec_fn != Py_None) &&
(_PyInterpreterState_Get() != PyInterpreterState_Main())) {
PyErr_SetString(PyExc_RuntimeError,
"preexec_fn not supported within subinterpreters");
return NULL;
}

Expand Down

0 comments on commit 98d90f7

Please sign in to comment.