This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients gregory.p.smith, izbyshev, nanjekyejoannah, pablogsal, pitrou, serhiy.storchaka, vstinner
Date 2018-12-20.21:45:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I wasn't sure how posix_spawn() handles file descriptors of standard streams with O_CLOEXEC flag set.

I wrote a test. Result: _posixsubprocess and os.posix_spawn() have the same behavior! If fd 2 (stderr) is marked with O_CLOEXEC, the fd 2 is closed in the child process, as expected. (There is no black magic to keep it open.)

$ cat 
import subprocess, sys, os
args = [sys.executable, '']
os.set_inheritable(2, False), close_fds=False, restore_signals=False)

$ cat 
import os
def fd_valid(fd):
        return True
    except OSError:
        return False
for fd in (0, 1, 2):
    print("fd %s valid? %s" % (fd, fd_valid(fd)))

$ python3  # unpatched
fd 0 valid? True
fd 1 valid? True
fd 2 valid? False

$ ./python # patched, use posix_spawn()
fd 0 valid? True
fd 1 valid? True
fd 2 valid? False
Date User Action Args
2018-12-20 21:45:36vstinnersetrecipients: + vstinner, gregory.p.smith, pitrou, serhiy.storchaka, izbyshev, pablogsal, nanjekyejoannah
2018-12-20 21:45:36vstinnersetmessageid: <>
2018-12-20 21:45:36vstinnerlinkissue35537 messages
2018-12-20 21:45:34vstinnercreate