3 \@sddlZddlZddlZddlZddlZddlmZddlmZddlm Z dgZ ej dkrxe dg7Z Gd dde Z ne d g7Z Gd d d e ZGd d d e ZeZejZdS)N)process) reduction)utilstopZwin32 DupSocketc@seZdZddZddZdS)rcs(|jfdd}tj|j|_dS)Ncsj|}|j|dS)N)shareZ send_bytes)connpidr)new_sock7/usr/lib64/python3.6/multiprocessing/resource_sharer.pysends z DupSocket.__init__..send)dup_resource_sharerregisterclose_id)selfZsockrr )r r __init__s zDupSocket.__init__c Cs*tj|j}|j}tj|SQRXdS)N)rget_connectionrZ recv_bytessocketZ fromshare)rr rr r r detach$szDupSocket.detachN)__name__ __module__ __qualname__rrr r r r rsDupFdc@seZdZddZddZdS)rcs4tj|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/s   zDupFd.__init__c Cs"tj|j }tj|SQRXdS)N)rrrrZ recv_handle)rr r r r r7sz DupFd.detachN)rrrrrr r r r r-sc@sJeZdZddZddZeddZddd Zd d Zd d Z ddZ dS)_ResourceSharercCs@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 CsN|j>|jdkr|j|jd7_||f|j|j<|j|jfSQRXdS)Nr)r&r(_startr!r")rrrr r r rIs  z_ResourceSharer.registercCs<ddlm}|\}}||tjjd}|j|tjf|S)Nr)Client)authkey) connectionr,rcurrent_processr-rrgetpid)Zidentr,addresskeycr r r rRs  z_ResourceSharer.get_connectionNc Csddlm}|j|jdk r||jtjjd}|jd|j|j j ||j j rdt j d|jjd|_ d|_d|_x |jjD]\}\}}|qW|jjWdQRXdS)Nr)r,)r-z._ResourceSharer thread did not stop when asked)r.r,r&r(rr/r-rrr)joinZis_aliverZ sub_warningr'r"itemsclear)rZtimeoutr,r3r2rrr r r r[s"        z_ResourceSharer.stopcCsnx |jjD]\}\}}|q W|jj|jj|jtj|_|jdk rX|jj d|_d|_ d|_ dS)N) r"r5r6r#appendr&r$r%r'rr(r))rr2rrr r r r*ps     z_ResourceSharer._afterforkcCsXddlm}tjd|tjjd|_|jj|_ t j |j d}d|_ |j||_dS)Nr)Listenerz0starting listener and thread for sending handles)r-)targetT)r.r8rdebugrr/r-r'r1r(r$ZThread_serveZdaemonstartr))rr8tr r r r+~s   z_ResourceSharer._startcCsttdr tjtjtdtjxy\|jjH}|j}|dkrBP|\}}|j j |\}}z|||Wd|XWdQRXWq"t j st jt jYq"Xq"WdS)Npthread_sigmaskr)hasattrsignalr> SIG_BLOCKrangeNSIGr'ZacceptZrecvr"poprZ is_exitingsys excepthookexc_info)rr msgr2Zdestination_pidrrr r r r;s   z_ResourceSharer._serve)N) rrrrr staticmethodrrr*r+r;r r r r r =s   r )rr@rrEr$rcontextrr__all__platformobjectrrr rrr r r r  s       `