original) (raw)
(Agreed that guessing whether something's a handle or not is terrible. If this is truly only for sockets then maybe it should live in the socket module?
Also, are you sure the things returned by socket.fleno() are really Windows handles? I thought they were some other artificial namespace used just by sockets.On Tue, Aug 20, 2013 at 4:30 PM, Victor Stinner <victor.stinner@gmail.com> wrote:
Hi,
I have a new question for my PEP 446 (inheritance of file descriptors).
os.get/set\_inheritable(handle) has strange behaviour on Windows, and
so I would like to add new os.get/set\_handle\_inheritable() functions
to avoid it. The problem is that a socket would require a different
function depending on the OS: os.get/set\_handle\_inheritable() on
Windows, os.get/set\_inheritable() on UNIX. Should I add a portable
helper to the socket module (socket.get/set\_inheritable)? Or add 2
methods to the socket class?
Now the details.
I have an issue with sockets and the PEP 446\. On Windows, my
implementation of the os.set\_inheritable(fd: int, inheritable: bool)
function tries to guess if fd is a file descriptor or a handle. The
reason is that the fileno() method of a socket returns a file
descriptor on UNIX, whereas it returns a handle on Windows. It is
convinient to have a os.set\_interiable() function which accepts both
types.
The issue is that os.get\_inheritable() does the same guess and it has
a strange behaviour. Calling os.get\_inheritable() with integers in the
range(20) has a border effect: open(filename) creates a file
descriptor 10, whereas it creates a file descriptor 3 if
get\_inheritable() was not called (why 10 and not 3?).
To avoid the border effect, it's better to not guess if the parameter
is a file descriptor or a Windows handle, and a new two new functions:
os.get\_handle\_inheritable() and os.set\_handle\_inheritable().
Victor
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
--
--Guido van Rossum (python.org/\~guido)