[Python-Dev] (New) PEP 446: Make newly created file descriptors non-inheritable

Victor Stinner victor.stinner at gmail.com
Mon Aug 12 03:12:17 CEST 2013

2013/8/12 Victor Stinner <victor.stinner at gmail.com>:
> I fixed various bugs in the implementation of the (new) PEP 446:
> http://hg.python.org/features/pep-446
> At revision da685bd67524, the full test suite pass on: (...)

I also checked the usage of atomic flags. There was a minor bug on
Linux, it is now fixed (remove an useless call to fcntl to check if

open(): On Linux, FreeBSD and Solaris 11, O_CLOEXEC flag is used.
fcntl(F_GETFD) is only called once for all file descriptors, to check
if O_CLOEXEC works. On Windows, O_NOINHERIT is used.

socket.socket(): On Linux, SOCK_CLOEXEC flag is used, no extra syscall
is required.

os.pipe(): On Linux, pipe2() is used with O_CLOEXEC.

On other platforms, os.set_inheritable() must be called to make the
new file descriptors non-inheritables.

On Windows, the atomic flag WSA_FLAG_NO_HANDLE_INHERIT is not used to
create a socket. I don't know the Windows well enough to make such

My OpenIndiana VM looks to be older than Solaris 11: O_CLOEXEC flag is missing.

I regenerated the patch in the isssue: http://bugs.python.org/issue18571


More information about the Python-Dev mailing list