3 \!@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddl m Z ddlm Z ddlmZddlmZd d d d gZd ZejdZGdddeZdddZddZddZddZeZejZejZejZejZdS)N) connection)process) reduction)semaphore_tracker)spawn)utilensure_runningget_inherited_fdsconnect_to_new_processset_forkserver_preloadQc@s4eZdZddZddZddZddZd d Zd S) ForkServercCs.d|_d|_d|_d|_tj|_dg|_dS)N__main__)_forkserver_address_forkserver_alive_fd_forkserver_pid_inherited_fds threadingZLock_lock_preload_modules)selfr2/usr/lib64/python3.6/multiprocessing/forkserver.py__init__!s  zForkServer.__init__cCs&tdd|jDstd||_dS)z>Set list of module names to try to load in forkserver process.css|]}t|tkVqdS)N)typestr).0modrrr +sz4ForkServer.set_forkserver_preload..z&module_names must be a list of stringsN)allr TypeError)rZ modules_namesrrrr )sz!ForkServer.set_forkserver_preloadcCs|jS)zReturn list of fds inherited from parent process. This returns None if the current process was not started by fork server. )r)rrrrr /szForkServer.get_inherited_fdscCs|jt|dtkr tdtjtj}|j|jtj \}}tj \}}|||j t j g}||7}z.r(iz-czCfrom multiprocessing.forkserver import main; main(%d, %d, %r, **%r))rrr rr)waitpidWNOHANGr+rrrrZget_preparation_datadictitemsr'r(rZarbitrary_addressZbindchmodZlistenr*filenoZget_executablerZ_args_from_interpreter_flagsZspawnv_passfds) rpidZstatuscmddatalistenerZaddressalive_rZalive_wZ fds_to_passZexeargsr)r4rr TsL             zForkServer.ensure_runningN)__name__ __module__ __qualname__rr r r r rrrrrs rc4Cs|rhd|kr8|dk r8dtj_ztj|Wdtj`Xx.|D]&}y t|Wq>tk rbYq>Xq>Wtjt j t j t j t j i}dd|j D}tjtj|dR}tj<} |jt_| j|tj| j|tjx yxdd| jD} | rPqW|| kr$tj|d d ks tt|| ks2t|jd l} d } tjd krzFyt| |||Wn.tk rt j!t j"t j#j$YnXWdtj%| XWdQRXWqt&k r} z| j't'j(krւWYdd} ~ XqXqWWdQRXWdQRXdS) zRun forkserver.rNTcSsi|]\}}tj|||qSr)signal)rsigvalrrr szmain..)r:cSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrr szmain..rr))rZcurrent_processZ _inheritingrZimport_main_path __import__ ImportErrorrZ _close_stdinrDSIGCHLDSIG_IGNSIGINTr8r'r( selectorsZDefaultSelectorZ getsockname _forkserverrregisterZ EVENT_READZselectr)readAssertionError SystemExitZacceptfork _serve_one Exceptionsys excepthookexc_infostderrflush_exitOSErrorerrnoZ ECONNABORTED)Z listener_fdr?Zpreloadr/r0modnamehandlersZ old_handlersr>ZselectorZrfdsscodeerrrmainsV          rfc Cs|jtj|x |jD]\}}tj||qWtj|td}|jt|tks\t|^}}t _ } t _ | t j _t|tjdtjkrddl} | jtj|} t|| dS)Nrrandomr)r+r)r8rDrZrecvfdsr%r$rTrQrrrZ_semaphore_trackerZ_fdwrite_unsignedgetpidrYmodulesrgZseedr_main) rcr>r?rbrErFr,r.r-ZstfdrgrdrrrrWs   rWcCsRd}tj}x8t||krBtj||t|}|s8td||7}q Wtj|dS)NrJzunexpected EOFr)UNSIGNED_STRUCTsizer$r)rSEOFErrorZunpack)fdr=Zlengthrcrrr read_unsigneds rpcCs@tj|}x0|r:tj||}|dkr,td||d}q WdS)Nrzshould not get here)rlZpackr)write RuntimeError)ronmsgnbytesrrrrhs   rh)NN)r`r)rPrDr'ZstructrYrrrcontextrrrr__all__r%ZStructrlobjectrrfrWrprhrQr r r r rrrrs6       s =!