[Python-Dev] PEP 446: issue with sockets

Guido van Rossum guido at python.org
Wed Aug 21 01:57:46 CEST 2013


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 at 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 at 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130820/f2fa3cf9/attachment.html>


More information about the Python-Dev mailing list