]> granicus.if.org Git - python/commitdiff
bpo-37951: Lift subprocess's fork() restriction (GH-15544)
authorChristian Heimes <christian@python.org>
Tue, 27 Aug 2019 21:36:56 +0000 (23:36 +0200)
committerGitHub <noreply@github.com>
Tue, 27 Aug 2019 21:36:56 +0000 (23:36 +0200)
Doc/library/subprocess.rst
Doc/whatsnew/3.8.rst
Misc/NEWS.d/next/Library/2019-08-27-10-03-48.bpo-37951.MfRQgL.rst [new file with mode: 0644]
Modules/_posixsubprocess.c

index 7e1e3f942c1c331394913a4b2f504c7fbedde145..167ed9a6ead497dbb500a16de69de1d128a21f48 100644 (file)
@@ -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
index cd31cf6db6e897c439aa8f8c9982ed232db1c38f..bcdb60d86d855346eadb1af090b4e9014cd292c0 100644 (file)
@@ -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.
 
diff --git a/Misc/NEWS.d/next/Library/2019-08-27-10-03-48.bpo-37951.MfRQgL.rst b/Misc/NEWS.d/next/Library/2019-08-27-10-03-48.bpo-37951.MfRQgL.rst
new file mode 100644 (file)
index 0000000..18e4c62
--- /dev/null
@@ -0,0 +1,2 @@
+Most features of the subprocess module now work again in subinterpreters.
+Only *preexec_fn* is restricted in subinterpreters.
index 60c8eab90a15cf722c6ecfe5d4a10a7c2d44946b..f68d362acc04719001ac34a4e66c3a4b8de15f36 100644 (file)
@@ -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;
     }