U e5dèã@s²ddlZddlZddlZddlZddlZddlmZddlmZddlm Z dgZ ej dkrxe dg7Z Gd d„de ƒZ ne d g7Z Gd d „d e ƒZGd d „d e ƒZeƒZejZdS)éNé)Úprocess)Ú reduction)ÚutilÚstopZwin32Ú DupSocketc@seZdZdd„Zdd„ZdS)rcs(| ¡‰‡fdd„}t |ˆj¡|_dS)Ncsˆ |¡}| |¡dS©N)ÚshareZ send_bytes)ÚconnÚpidr ©Znew_sock©ú7/usr/lib64/python3.8/multiprocessing/resource_sharer.pyÚsends z DupSocket.__init__..send)ÚdupÚ_resource_sharerÚregisterÚcloseÚ_id)ÚselfZsockrr r rÚ__init__s zDupSocket.__init__c Cs6t |j¡ }| ¡}t |¡W5QR£SQRXdSr)rÚget_connectionrZ recv_bytesÚsocketZ fromshare)rr r r r rÚdetach$szDupSocket.detachN©Ú__name__Ú __module__Ú __qualname__rrr r r rrsÚDupFdc@seZdZdd„Zdd„ZdS)rcs4t |¡‰‡fdd„}‡fdd„}t ||¡|_dS)Ncst |ˆ|¡dSr)rZ send_handle)r r ©Znew_fdr rr1szDupFd.__init__..sendcst ˆ¡dSr)Úosrr rr rr3szDupFd.__init__..close)r rrrr)rÚfdrrr rrr/s   zDupFd.__init__c Cs.t |j¡}t |¡W5QR£SQRXdSr)rrrrZ recv_handle)rr r r rr7sz DupFd.detachNrr r r rr-sc@sJeZdZdd„Zdd„Zedd„ƒZddd „Zd d „Zd d „Z dd„Z dS)Ú_ResourceSharercCs@d|_i|_g|_t ¡|_d|_d|_d|_t   |t j ¡dS)Nr) Ú_keyÚ_cacheÚ _old_locksÚ threadingÚLockÚ_lockÚ _listenerÚ_addressÚ_threadrZregister_after_forkr"Ú _afterfork)rr r rr?s z_ResourceSharer.__init__c CsZ|jJ|jdkr| ¡|jd7_||f|j|j<|j|jfW5QR£SQRXdS)Nr)r(r*Ú_startr#r$)rrrr r rrIs  z_ResourceSharer.registercCs<ddlm}|\}}||t ¡jd}| |t ¡f¡|S)Nr©ÚClient©Úauthkey)Ú connectionr/rÚcurrent_processr1rr Úgetpid)Zidentr/ÚaddressÚkeyÚcr r rrRs  z_ResourceSharer.get_connectionNc Cs¶ddlm}|jš|jdk r¨||jt ¡jd}| d¡| ¡|j   |¡|j   ¡rdt   d¡|j ¡d|_ d|_d|_|j ¡D]\}\}}|ƒqŠ|j ¡W5QRXdS)Nrr.r0z._ResourceSharer thread did not stop when asked)r2r/r(r*rr3r1rrr+ÚjoinZis_aliverZ sub_warningr)r$ÚitemsÚclear)rZtimeoutr/r7r6rrr r rr[s$  ÿ     z_ResourceSharer.stopcCsj|j ¡D]\}\}}|ƒq |j ¡|j |j¡t ¡|_|jdk rT|j  ¡d|_d|_ d|_ dSr) r$r9r:r%Úappendr(r&r'r)rr*r+)rr6rrr r rr,ps    z_ResourceSharer._afterforkcCsXddlm}t d¡|t ¡jd|_|jj|_ t j |j d}d|_ | ¡||_dS)Nr)ÚListenerz0starting listener and thread for sending handlesr0)ÚtargetT)r2r<rÚdebugrr3r1r)r5r*r&ZThreadÚ_serveZdaemonÚstartr+)rr<Útr r rr-~s   z_ResourceSharer._startc Cs®ttdƒrt tjt ¡¡zh|j ¡T}| ¡}|dkrHW5QR£Wqª|\}}|j  |¡\}}z|||ƒW5|ƒXW5QRXWqt   ¡s¢t j t  ¡ŽYqXqdS)NÚpthread_sigmask)ÚhasattrÚsignalrBÚ SIG_BLOCKÚ valid_signalsr)ZacceptZrecvr$ÚpoprZ is_exitingÚsysÚ excepthookÚexc_info)rr Úmsgr6Zdestination_pidrrr r rr?‰s  z_ResourceSharer._serve)N) rrrrrÚ staticmethodrrr,r-r?r r r rr"=s     r")r rDrrHr&ÚrÚcontextrrÚ__all__ÚplatformÚobjectrrr"rrr r r rÚ s       `