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)Ncss|]}t|tkVqdS)N)typestr).0modrrr +sz4ForkServer.set_forkserver_preload..z&module_names must be a list of strings)allr TypeError)rZ modules_namesrrrr )sz!ForkServer.set_forkserver_preloadcCs|jS)N)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|d,}tj} |jt_| j|tj| j|tjxyxdd| jD} | rPqW|| kr t|jdl} d } tjdkrzFyt| |||Wn.tk rntjtj tj!j"YnXWdtj#| XWdQRXWqt$k r} z| j%t%j&krWYdd} ~ XqXqWWdQRXWdQRXdS) NrTcSsi|]\}}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_READZselect SystemExitZacceptr)fork _serve_one Exceptionsys excepthookexc_infostderrflush_exitOSErrorerrnoZ ECONNABORTED)Z listener_fdr?Zpreloadr/r0modnamehandlersZ old_handlersr>ZselectorZrfdsscodeerrrmainsR          rcc Cs|jtj|x |jD]\}}tj||qWtj|td}|j|^}}t_} t_ | t j _ t |tjdtjkrddl} | jtj|} t || dS)Nrrandomr)r+r)r8rDrZrecvfdsr%rPrrrZ_semaphore_trackerZ_fdwrite_unsignedgetpidrVmodulesrdZseedr_main) r`r>r?r_rErFr,r.r-ZstfdrdrarrrrTs   rTcCsRd}tj}x8t||krBtj||t|}|s8td||7}q Wtj|dS)Nzunexpected EOFr)UNSIGNED_STRUCTsizer$r)readEOFErrorZunpack)fdr=Zlengthr`rrr read_unsigneds rocCs@tj|}x0|r:tj||}|dkr,td||d}q WdS)Nrzshould not get here)rjZpackr)write RuntimeError)rnnmsgnbytesrrrres   re)NN)r]r)rOrDr'ZstructrVrrrcontextrrrr__all__r%ZStructrjobjectrrcrTrorerPr r r r rrrrs6       s =!