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 neologix, vstinner
Date 2013-01-04.14:22:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
os.O_CLOEXEC has been added to Python 3.3. This flag solves a race condition if the process is forked between open() and a call to fcntl() to set the FD_CLOEXEC flag.

The following patch written by neologix should fix this issue:
diff --git a/Lib/ b/Lib/
--- a/Lib/
+++ b/Lib/
@@ -57,6 +57,8 @@
 _allocate_lock = _thread.allocate_lock

 _text_openflags = _os.O_RDWR | _os.O_CREAT | _os.O_EXCL
+if hasattr(_os, 'O_CLOEXEC'):
+    _text_openflags |= _os.O_CLOEXEC
 if hasattr(_os, 'O_NOINHERIT'):
     _text_openflags |= _os.O_NOINHERIT
 if hasattr(_os, 'O_NOFOLLOW'):

The patch can be applied to Python 3.3 and 3.4.
Date User Action Args
2013-01-04 14:22:29vstinnersetrecipients: + vstinner, neologix
2013-01-04 14:22:29vstinnersetmessageid: <>
2013-01-04 14:22:29vstinnerlinkissue16860 messages
2013-01-04 14:22:28vstinnercreate