[@sddlZddlZddlZddlZddlZddlmZddlmZddlmZdgZ ej dkre dg7Z Gd dde Z n#e d g7Z Gd d d e Z Gd d d e ZeZejZdS)N)process) reduction)utilstopZwin32 DupSocketc@s.eZdZdZddZddZdS)rzPicklable wrapper for a socket.cs:|jfdd}tj|j|_dS)Ncs j|}|j|dS)N)shareZ send_bytes)connpidr)new_sock5/usr/lib/python3.4/multiprocessing/resource_sharer.pysendsz DupSocket.__init__..send)dup_resource_sharerregisterclose_id)selfZsockrr )r r __init__s zDupSocket.__init__c Cs8tj|j }|j}tj|SWdQXdS)z1Get the socket. This should only be called once.N)rget_connectionrZ recv_bytessocketZ fromshare)rr rr r r detach$s zDupSocket.detachN)__name__ __module__ __qualname____doc__rrr r r r rs  DupFdc@s.eZdZdZddZddZdS)rz-Wrapper for fd which can be used at any time.csLtj|fdd}fdd}tj|||_dS)Ncstj||dS)N)rZ send_handle)r r )new_fdr r r1szDupFd.__init__..sendcstjdS)N)osrr )rr r r3szDupFd.__init__..close)rrrrr)rfdrrr )rr r/szDupFd.__init__c Cs,tj|j}tj|SWdQXdS)z-Get the fd. This should only be called once.N)rrrrZ recv_handle)rr r r r r7sz DupFd.detachN)rrrrrrr r r r r-s  c@sseZdZdZddZddZeddZdd d Zd d Z d dZ ddZ dS)_ResourceSharerz-Manager for resouces using background thread.cCs\d|_i|_g|_tj|_d|_d|_d|_t j |t j dS)Nr) _key_cache _old_locks threadingLock_lock _listener_address_threadrZregister_after_forkr! _afterfork)rr r r r?s      z_ResourceSharer.__init__c Cse|jV|jdkr&|jn|jd7_||f|j|j<|j|jfSWdQXdS)z+Register resource, returning an identifier.Nr)r'r)_startr"r#)rrrr r r rIs   z_ResourceSharer.registercCsTddlm}|\}}||dtjj}|j|tjf|S)z s        `