Picklable wrapper for a socket.
| 25 | __all__ += ['DupSocket'] |
| 26 | |
| 27 | class DupSocket(object): |
| 28 | '''Picklable wrapper for a socket.''' |
| 29 | def __init__(self, sock): |
| 30 | new_sock = sock.dup() |
| 31 | def send(conn, pid): |
| 32 | share = new_sock.share(pid) |
| 33 | conn.send_bytes(share) |
| 34 | self._id = _resource_sharer.register(send, new_sock.close) |
| 35 | |
| 36 | def detach(self): |
| 37 | '''Get the socket. This should only be called once.''' |
| 38 | with _resource_sharer.get_connection(self._id) as conn: |
| 39 | share = conn.recv_bytes() |
| 40 | return socket.fromshare(share) |
| 41 | |
| 42 | else: |
| 43 | __all__ += ['DupFd'] |
no outgoing calls
no test coverage detected
searching dependent graphs…