Eryk Sun added the comment:

You should be able to directly pass the socket to the child process. 
multiprocessing registers a reduction for this. On Windows it uses the 
DupSocket class from multiprocessing.resource_sharer:

    class DupSocket(object):
        '''Picklable wrapper for a socket.'''
        def __init__(self, sock):
            new_sock = sock.dup()
            def send(conn, pid):
                share = new_sock.share(pid)
                conn.send_bytes(share)
            self._id = _resource_sharer.register(send, new_sock.close)

        def detach(self):
            '''Get the socket.  This should only be called once.'''
            with _resource_sharer.get_connection(self._id) as conn:
                share = conn.recv_bytes()
                return socket.fromshare(share)

This calls the Windows socket share() method [1], which calls 
WSADuplicateSocket [2]. In the child, socket.fromshare() passes the protocol 
info buffer to the socket constructor, which passes it to WSASocket [3].

[1]: https://docs.python.org/3/library/socket.html#socket.socket.share
[2]: https://msdn.microsoft.com/en-us/library/ms741565
[3]: https://msdn.microsoft.com/en-us/library/ms742212

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28906>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to