[3.6] bpo-32270: Don't close stdin/out/err in pass_fds (GH-6242) by miss-islington · Pull Request #9149 · python/cpython (original) (raw)
When subprocess.Popen() stdin= stdout= or stderr= handles are specified
and appear in pass_fds=, don't close the original fds after dup'ing them.
This implementation and unittest primarily came from @izbyshev (see the PR)
See also izbyshev@b89b52f
This also removes the old manual p2cread, c2pwrite, and errwrite closing logic
as inheritable flags and _close_open_fds takes care of that properly today without special treatment.
This code is within child_exec() where it is the only thread so there is no
race condition between the dup and _Py_set_inheritable_async_safe call.
(cherry picked from commit ce34410)
Co-authored-by: Gregory P. Smith greg@krypto.org