[Python-Dev] Add "e" (close and exec) mode to open()

Victor Stinner victor.stinner at gmail.com
Tue Jan 8 12:56:52 CET 2013


2013/1/8 Victor Stinner <victor.stinner at gmail.com>:
> I don't know platform without this flag.

According to the following email, fcntl.FD_CLOEXEC was not available
in Python 2.2 on Red Hat 7.3 (in 2003):
http://communities.mentor.com/community/cs/archives/qmtest/msg00501.html

I don't know if the constant was not defined in fcntl.h, or if the
constant was just not exposed in Python 2.2?

Does anyone have such old version of RedHat to test if
fcntl.FD_CLOEXEC is available (on a recent version of Python)?

--

In the Python issue #12107, I can read:
"I realize this bugreport cannot fix 35 years of a bad design decision
in linux."
http://bugs.python.org/issue12107

Well... Ruby made a brave choice :-) Ruby (2.0?) does set
close-on-exec flag on *ALL file descriptors (except 0, 1, 2) *by
default*:
http://bugs.ruby-lang.org/issues/5041

This change solves the problem of having to close all file descriptor
after a fork to run a new program (see closed Python issues #11284 and
#8052)... if you are not using C extensions creating file descriptors?

Ruby applications relying on passing FD to child processes have to
explicitly disable close-on-exec the flag: it was done in Unicorn for
example.

--

See also the issue discussing the usage of O_CLOEXEC and SOCK_CLOEXEC
in the libapr:
https://issues.apache.org/bugzilla/show_bug.cgi?id=46425

Victor


More information about the Python-Dev mailing list