[Python-Dev] PEP 446: issue with sockets

Richard Oudkerk shibturn at gmail.com
Wed Aug 21 15:11:41 CEST 2013


On 21/08/2013 1:50pm, Victor Stinner wrote:
> 2013/8/21 Richard Oudkerk <shibturn at gmail.com>:
>> On 21/08/2013 1:19am, Victor Stinner wrote:
>>> I don't know if a socket handle is similar to file handles or if they
>>> are specials. At least, GetHandleInformation() and
>>> SetHandleInformation() functions, used by
>>> os.get/set_handle_inheritable(), accept socket handles.
>>
>> Anti-virus software and firewalls can stop SetHandleInformation() from
>> working properly on sockets:
>>
>> http://stackoverflow.com/questions/12058911/can-tcp-socket-handles-be-set-not-inheritable
>
> Yeah, I know, I already added the link to the PEP.
>
> I improved the implementation of the PEP 446: it now uses the
> WSA_FLAG_NO_HANDLE_INHERIT flag when it is available (Windows 7 SP1
> and Windows Server 2008 R2 SP1, which is probably a minor percentage
> of Windows installations).
>
> On older Windows versions, I don't see what Python can do to
> workaround the issue except of calling SetHandleInformation() on the
> result of WSASocket().
>
> Victor
>

If the socket methods are not guaranteed to work then they should come 
with a nice big warning to that effect.

It seems that the only reliable way for a parent process to give a 
socket to a child process is to use WSADuplicateSocket().  (But that 
requires communication between parent and child after the child has 
started.)

--
Richard


More information about the Python-Dev mailing list