[Python-Dev] PEP 446: Add new parameters to configure the inherance of files and for non-blocking sockets (original) (raw)

Victor Stinner victor.stinner at gmail.com
Sun Jul 7 15:21:01 CEST 2013


2013/7/7 Charles-François Natali <cf.natali at gmail.com>:

2013/7/7 Cameron Simpson <cs at zip.com.au>:

On 06Jul2013 11:23, Charles-François Natali <cf.natali at gmail.com> wrote: | > I've read your "Rejected Alternatives" more closely and Ulrich | > Drepper's article, though I think the article also supports adding | > a blocking (default True) parameter to open() and os.open(). If you | > try to change that default on a platform where it doesn't work, an | > exception should be raised. | | Contrarily to close-on-exec, non-blocking only applies to a limited | type of files (e.g. it doesn't work for regular files, which represent | 90% of open() use cases).

sockets, pipes, serial devices, ... How do you use open() on a socket (which are already covered by socket(blocking=...)? Also, I said regular files - for which ONONBLOCK doesn't make sense - represent 90% of io.open() use cases, and stand by this claim. Nothing prevents you from setting the FD non-blocking manually.

Ok, I think that the best consensus here is to add a new os.set_blocking() function. The function would not be available on Windows, but should be available on all UNIX platforms. The advantage of os.set_blocking() over fcntl is that it may be implemented using ioctl (FIONBIO) to use 1 syscall instead of 2. It is also easier to remember calling "os.set_blocking(fd, True)" instead of "fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fcntl.F_GETFL, fd) | os.O_NONBLOCK)".

See the diff: http://hg.python.org/peps/rev/ce61588d244c

@Charles-François and Cameron: Do you prefer to new version of the PEP? http://www.python.org/dev/peps/pep-0446/ (will be updated in a few minutes)

I'm not sure that many people are concerned by the number of syscalls, but there is at least Peter Portante who opened a thread "Modules/socketmodule.c: avoiding second fcntl() call worth the effort?" on this mailing list, last January: http://mail.python.org/pipermail/python-dev/2013-January/123661.html "OpenStack Swift using the Eventlet module, which sets the accepted socket non-blocking, resulting in twice the number of fcntl() calls. Not a killer on performance, but it seems simple enough to save a system call here."

(This specific issue will be solved by the new blocking parameter added to socket constructor ;-))

Victor



More information about the Python-Dev mailing list