classification
Title: Document how to use open with os.O_CLOEXEC
Type: behavior Stage:
Components: Documentation Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: docs@python Nosy List: christian.heimes, docs@python, eric.araujo, socketpair, vstinner
Priority: normal Keywords: easy

Created on 2011-05-18 11:01 by socketpair, last changed 2013-01-03 16:31 by christian.heimes. This issue is now closed.

Messages (5)
msg136223 - (view) Author: Марк Коренберг (socketpair) * Date: 2011-05-18 11:01
open() and friends (like temporaryfile) does not document 'e' letter in second arguement. At least on Linux, it opens file with O_CLOEXEC.
Not sure under Windows.

Also, there are other interesting letters (man -a fopen), like:

c (since glibc 2.3.3)
       Do not make the open operation, or  subsequent  read  and  write operations, thread cancellation points.
e (since glibc 2.7)
       Open  the  file  with  the O_CLOEXEC flag.  See open(2) for more information.
m (since glibc 2.3)
       Attempt to access the file using mmap(2), rather than I/O system calls  (read(2),  write(2)).   Currently, use of mmap(2) is only attempted for a file opened for reading.

x      Open the file exclusively (like the O_EXCL flag of open(2)).  If the  file  already exists, fopen() fails, and sets errno to EEXIST.  This flag is ignored for fdopen().
msg136225 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-18 11:16
c, e, m and x flags are specific to the GNU libc. Python 2 does basically pass the mode to fopen() unmodified (there is one exception, the U flag). fopen() of Visual C++ 2005 has other flags:

c
Enable the commit flag for the associated filename so that the contents of the file buffer are written directly to disk if either fflush or _flushall is called.

n
Reset the commit flag for the associated filename to "no-commit." This is the default. It also overrides the global commit flag if you link your program with COMMODE.OBJ. The global commit flag default is "no-commit" unless you explicitly link your program with COMMODE.OBJ (see Link Options).

N
Specifies that the file is not inherited by child processes.

S
Specifies that caching is optimized for, but not restricted to, sequential access from disk.

R
Specifies that caching is optimized for, but not restricted to, random access from disk.

T
Specifies a file as temporary. If possible, it is not flushed to disk.

D
Specifies a file as temporary. It is deleted when the last file pointer is closed.

ccs=ENCODING
Specifies the coded character set to use (UTF-8, UTF-16LE, or UNICODE) for this file. Leave unspecified if you want ANSI encoding. This option is available in Visual C++ 2005 and later.

http://msdn.microsoft.com/en-us/library/yeby3zcb(v=vs.80).aspx

I don't think that non standard modes should be documented in Python doc, but we may add links to specific documentations like the GNU libc and Microsoft fopen().

--

This issue is specific to Python 2, Python 3 doesn't use fopen() anymore.
msg136526 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-22 13:58
Issue #12105 adds os.O_CLOEXEC flag, so we will be able to write open(os.open(filename, os.O_RDONLY|os.O_CLOEXEC)). Do you want to work on a doc patch?
msg178954 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-01-03 15:33
> x      Open the file exclusively (like the O_EXCL flag of open(2)).
>  If the  file  already exists, fopen() fails, and sets errno to EEXIST.
> This flag is ignored for fdopen().

Python 3.3 adds support for this mode: see issue #12760.

> e (since glibc 2.7)
>       Open  the  file  with  the O_CLOEXEC flag.  See open(2) for more information.

I created the issue #16850 for this mode.

--

Other modes seem to be very specific to some platforms. I don't think that it would be possible to expose them in a portable way using the open() function directly.

Can we close this issue? I prefer to work on #16850 for the close-on-exec mode.
msg178961 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-01-03 16:31
Sounds good to me.
History
Date User Action Args
2013-01-03 16:31:47christian.heimessetstatus: open -> closed

nosy: + christian.heimes
messages: + msg178961

resolution: out of date
2013-01-03 15:33:43vstinnersetmessages: + msg178954
2011-11-12 13:45:07eric.araujosetkeywords: + easy
nosy: + eric.araujo
title: Documentation of open() does not claim 'e' support in mode string -> Document how to use open with os.O_CLOEXEC

versions: + Python 3.3, - Python 2.7
2011-05-22 13:58:59vstinnersetmessages: + msg136526
2011-05-18 11:16:07vstinnersetnosy: + vstinner

messages: + msg136225
versions: + Python 2.7
2011-05-18 11:01:37socketpairsettype: behavior
2011-05-18 11:01:24socketpaircreate