bpo-32270: Don't close stdin/out/err in pass_fds by gpshead · Pull Request #6242 · python/cpython (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there is no need to manually close p2cread
at all, and other two descriptors need to be closed only if they are the result of dup
above. This is because if a descriptor is created by subprocess.py (a pipe or for /dev/null
), it's non-inheritable, and if a descriptor is specified by the user, is not in pass_fds
and is > 2, it will be closed by _close_open_fds
. So my original idea of fixing this issue was to add an async-signal-safe version of _Py_dup
and use it instead of dup
above, and then just remove these three checks.
Note also that p2cwrite
and its three friends are never required to be manually closed since they are always non-inheritable pipe ends created by subprocess.py.