STINNER Victor added the comment:

In Python 3.3, open_noinherit_ctypes() can be written:

def opener_noinherit(filename, flags):
    return os.open(filename, flags | os.O_NOINHERIT)
f = open(filename, opener=opener_noinherit)


Example on Linux with O_CLOEXEC:

$ python3
Python 3.3.0 (default, Sep 29 2012, 22:07:38) 
[GCC 4.7.2 20120921 (Red Hat 4.7.2-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> def opener_noinherit(filename, flags):
...     return os.open(filename, flags | os.O_CLOEXEC)
... 
>>> f=open("/etc/issue", opener=opener_noinherit)
>>> import fcntl
>>> fcntl.fcntl(f.fileno(), fcntl.F_GETFD) & fcntl.FD_CLOEXEC
1

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19575>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to