8000 bpo-37951: Lift subprocess's fork() restriction (GH-15544) · python/cpython@03c52f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03c52f2

Browse files
bpo-37951: Lift subprocess's fork() restriction (GH-15544)
(cherry picked from commit 98d90f7) Co-authored-by: Christian Heimes <christian@python.org>
1 parent caf7a30 commit 03c52f2

File tree

4 files changed

+19
-2
lines changed
  • Misc/NEWS.d/next/Library
  • Modules
  • 4 files changed

    +19
    -2
    lines changed

    Doc/library/subprocess.rst

    Lines changed: 7 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -483,6 +483,13 @@ functions.
    483483
    The *start_new_session* parameter can take the place of a previously
    484484
    common use of *preexec_fn* to call os.setsid() in the child.
    485485

    486+
    .. versionchanged:: 3.8
    487+
    488+
    The *preexec_fn* parameter is no longer supported in subinterpreters.
    489+
    The use of the parameter in a subinterpreter raises
    490+
    :exc:`RuntimeError`. The new restriction may affect applications that
    491+
    are deployed in mod_wsgi, uWSGI, and other embedded environments.
    492+
    486493
    If *close_fds* is true, all file descriptors except :const:`0`, :const:`1` and
    487494
    :const:`2` will be closed before the child process is executed. Otherwise
    488495
    when *close_fds* is false, file descriptors obey their inheritable flag

    Doc/whatsnew/3.8.rst

    Lines changed: 6 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1531,6 +1531,12 @@ Changes in the Python API
    15311531
    non-zero :attr:`~Popen.returncode`.
    15321532
    (Contributed by Joannah Nanjekye and Victor Stinner in :issue:`35537`.)
    15331533

    1534+
    * The *preexec_fn* argument of * :class:`subprocess.Popen` is no longer
    1535+
    compatible with subinterpreters. The use of the parameter in a
    1536+
    subinterpreter now raises :exc:`RuntimeError`.
    1537+
    (Contributed by Eric Snow in :issue:`34651`, modified by Christian Heimes
    1538+
    in :issue:`37951`.)
    1539+
    15341540
    * The :meth:`imap.IMAP4.logout` method no longer ignores silently arbitrary
    15351541
    exceptions.
    15361542

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,2 @@
    1+
    Most features of the subprocess module now work again in subinterpreters.
    2+
    Only *preexec_fn* is restricted in subinterpreters.

    Modules/_posixsubprocess.c

    Lines changed: 4 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -583,8 +583,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
    583583
    &restore_signals, &call_setsid, &preexec_fn))
    584584
    return NULL;
    585585

    586-
    if (_PyInterpreterState_Get() != PyInterpreterState_Main()) {
    587-
    PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
    586+
    if ((preexec_fn != Py_None) &&
    587+
    (_PyInterpreterState_Get() != PyInterpreterState_Main())) {
    588+
    PyErr_SetString(PyExc_RuntimeError,
    589+
    "preexec_fn not supported within subinterpreters");
    588590
    return NULL;
    589591
    }
    590592

    0 commit comments

    Comments
     (0)
    0