U e5dP$@s$ddlZddlZddlZddlZddlmZmZddlmZddlm Z ddlm Z ddd d d d d gZ ej dkrzdZ dZneeddZ ejdZerejejdanejadd Zdd ZddZddZdd Zd&ddZddZddZdd ZgZ dd Z!d!d"Z"d#d$Z#d%d Z$dS)'N)get_start_methodset_start_method)process) reduction)util_mainfreeze_supportset_executableget_executableget_preparation_dataget_command_lineimport_main_pathwin32Ffrozenzpythonservice.exez python.execCs|adSN _python_exe)Zexer-/usr/lib64/python3.8/multiprocessing/spawn.pyr )scCstSrrrrrrr -scCs$t|dkr|ddkrdSdSdS)z= Return whether commandline indicates we are forking r--multiprocessing-forkTFN)len)argvrrr is_forking4srcCsdttjr`i}tjddD]0}|d\}}|dkr@d||<qt|||<qtf|tdS)zE Run code for process object if this in not the main process rN=None)rsysrsplitint spawn_mainexit)kwdsargnamevaluerrrr >s   cKshttddr(tjdgdd|DSd}|ddd |D;}t}tg|d |dgSd S) zJ Returns prefix of command line used for spawning a child process rFrcSsg|] }d|qS)%s=%rr.0itemrrr Tsz$get_command_line..zWsz#get_command_line..z-cN)getattrr executableitemsjoinrZ_args_from_interpreter_flagsr)r"progZoptsrrrr Ns c Csttjstdtjdkrrddl}ddl}|dk rL||j|j Bd|}nd}t j ||d}| |t j}|}n"ddlm} || j_|}t |}t||} t| dS) z7 Run code specified by data received over pipe z Not forkingrrNF)source_processr)resource_tracker)rrrAssertionErrorplatformmsvcrt_winapiZ OpenProcessZ SYNCHRONIZEZPROCESS_DUP_HANDLErZ duplicateZopen_osfhandleosO_RDONLYr2Z_resource_trackerZ_fdduprr!) Z pipe_handleZ parent_pidZ tracker_fdr5r6r1Z new_handlefdparent_sentinelr2Zexitcoderrrr \s,     r c Cs`tj|ddd@}dt_z$tj|}t|tj|}W5t`XW5QRX| |S)NrbT)closefd) r7fdopenrcurrent_process _inheritingrpickleloadprepare _bootstrap)r;r<Z from_parentZpreparation_dataselfrrrrxs  cCsttddrtddS)NrAFa An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.)r,rr@ RuntimeErrorrrrr_check_not_importing_mainsrHcCstttjtjd}tjdk r2tj|d<t j }z| d}Wnt k r^Yn Xtj||<|j||t jtjttdt jd}t|jdd}|dk r||d<nft jd kststst|d d}|dk rtj |s tjdk r tj tj|}tj ||d <|S) zM Return info about parent needed by child to unpickle process object ) log_to_stderrauthkeyN log_levelr9)r$sys_pathsys_argvorig_dirdir start_method__main__r$init_main_from_namer__file__init_main_from_path)rHdictrZ_log_to_stderrrr@rJZ_loggerZgetEffectiveLevelrpathcopyindex ValueError ORIGINAL_DIRupdaterr7getcwdrmodulesr,__spec__r4WINEXE WINSERVICEisabsr/normpath)r$drLi main_moduleZ main_mod_name main_pathrrrr sD       cCsd|kr|dt_d|kr,|dt_d|krD|drDtd|kr^t|dd|krp|dt_ d|kr|dt_ d|krt |dd|kr|dt_ d |krt|d d d d |krt|d nd |krt|d dS)zE Try to get current process ready to unpickle process object r$rJrIrKrLrMrOrNrPT)ZforcerRrTN)rr@r$rJrrIZ get_loggerZsetLevelrrVrr7chdirrZr_fixup_main_from_name_fixup_main_from_path)datarrrrDs,   rDcCs~tjd}|dks|dr dSt|jdd|kr6dSt|td}t j |ddd}|j ||tjd<tjd<dS)NrQz .__main__r$ __mp_main__T)run_nameZ alter_sys) rr]endswithr,r^old_main_modulesappendtypes ModuleTyperunpyZ run_module__dict__r[)Zmod_name current_mainre main_contentrrrrhs    rhcCstjd}tjtj|d}|dkr.dSt|dd|krBdSt|t d}t j |dd}|j ||tjd<tjd<dS)NrQrZipythonrSrk)rl)rr]r7rVsplitextbasenamer,rnrorprqrrZrun_pathrsr[)rfrtZ main_namererurrrri s    ricCs t|dS)z< Set sys.modules['__main__'] to module at main_path N)ri)rfrrrr%s)NN)%r7rrrrpr9rrrcontextrr__all__r4r_r`r,r-lowerrmrVr/ exec_prefixrr r rr r r rrHr rnrDrhrirrrrr sD        2&