diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 696617697047d2..741cc4a5bb324f 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1390,6 +1390,10 @@ def _get_handles(self, stdin, stdout, stderr): errread, errwrite) + def _posix_spawn(self, args, executable): + """Execute program using os.posix_spawn().""" + self.pid = os.posix_spawn(executable, args, os.environ) + def _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, @@ -1414,6 +1418,21 @@ def _execute_child(self, args, executable, preexec_fn, close_fds, if executable is None: executable = args[0] + + if (os.path.dirname(executable) + and preexec_fn is None + and not close_fds + and not pass_fds + and cwd is None + and env is None + and p2cread == p2cwrite == -1 + and c2pread == c2pwrite == -1 + and errread == errwrite == -1 + and not restore_signals + and not start_new_session): + self._posix_spawn(args, executable) + return + orig_executable = executable # For transferring possible exec failure from child to parent. diff --git a/Misc/NEWS.d/next/Library/2018-12-20-16-24-51.bpo-35537.z4E7aA.rst b/Misc/NEWS.d/next/Library/2018-12-20-16-24-51.bpo-35537.z4E7aA.rst new file mode 100644 index 00000000000000..e86c3ab7fd16ea --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-12-20-16-24-51.bpo-35537.z4E7aA.rst @@ -0,0 +1 @@ +subprocess.Popen can now use posix_spawn() in some cases. \ No newline at end of file