f _P$@sddlZddlZddlZddlZddlmZmZddlmZddlm Z ddlm Z gdZ ej dkrpd Z d Zneed d Z ejd Zerejejd anejad dZddZddZddZddZd'ddZddZddZddZgZ 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.10/multiprocessing/spawn.pyr )sr cCstSrrrrrrr -sr cCs t|dkr|ddkrdSdS)z= Return whether commandline indicates we are forking r--multiprocessing-forkTFN)len)argvrrr is_forking4srcCshttjrdi}tjddD]0}|d\}}|dkr@d||<qt|||<qtdi|tdS)zE Run code for process object if this in not the main process rN=Noner)rsysrsplitint spawn_mainexit)kwdsargnamevaluerrrr >s  r cKsdttddr(tjdgdd|DSd}|ddd |D;}t}tg|d |dgS) zJ Returns prefix of command line used for spawning a child process rFrcSsg|] }d|qS)%s=%rr.0itemrrr Tz$get_command_line..zWr+z#get_command_line..z-cN)getattrr executableitemsjoinr_args_from_interpreter_flagsr)r"progZoptsrrrr Ns r c CsttjsJdtjdkrrddl}ddl}|durL||j|jBd|}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)rrrplatformmsvcrt_winapiZ OpenProcessZ SYNCHRONIZEZPROCESS_DUP_HANDLErZ duplicateopen_osfhandleosO_RDONLYr4_resource_trackerZ_fdduprr!) Z pipe_handleZ parent_pidZ tracker_fdr6r7r3Z new_handlefdparent_sentinelr4exitcoderrrr \s*     r c Cs|tj|dddR}dt_z,tj|}t|tj|}Wt`n t`0Wdn1sh0Y| |S)NrbT)closefd) r9fdopenrcurrent_process _inheritingrpickleloadprepare _bootstrap)r>r?Z from_parentZpreparation_dataselfrrrrxs  2rcCsttddrtddS)NrEFa 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-rrD RuntimeErrorrrrr_check_not_importing_mainsrLcCstttjtjd}tjdur2tj|d<t j }z| d}Wnt y\Yn 0tj||<|j||t jtjttdt jd}t|jdd}|dur||d<nft jd kststst|d d}|durtj |stjdurtj tj|}tj ||d <|S) zM Return info about parent needed by child to unpickle process object ) log_to_stderrauthkeyN log_levelr;)r$sys_pathsys_argvorig_dirdir start_method__main__r$init_main_from_namer__file__init_main_from_path)rLdictr_log_to_stderrrrDrN_loggergetEffectiveLevelrpathcopyindex ValueError ORIGINAL_DIRupdaterr9getcwdrmodulesr-__spec__r5WINEXE WINSERVICEisabsr0normpath)r$drPi main_moduleZ main_mod_name main_pathrrrr sD        r cCsd|vr|dt_d|vr,|dt_d|vrD|drDtd|vr^t|dd|vrp|dt_ d|vr|dt_ d|vrt |dd|vr|dt_ d |vrt|d d d d |vrt|d nd |vrt|d dS)zE Try to get current process ready to unpickle process object r$rNrMrOrPrQrSrRrTT)forcerVrXN)rrDr$rNrrM get_loggersetLevelrr]rr9chdirrar_fixup_main_from_name_fixup_main_from_path)datarrrrHs,   rHcCs~tjd}|dks|dr dSt|jdd|kr6dSt|td}t j |ddd}|j ||tjd<tjd<dS)NrUz .__main__r$ __mp_main__T)run_name alter_sys) rrdendswithr-reold_main_modulesappendtypes ModuleTyperunpy run_module__dict__rb)mod_name current_mainrl main_contentrrrrrs    rrcCstjd}tjtj|d}|dkr.dSt|dd|krBdSt|t d}t j |dd}|j ||tjd<tjd<dS)NrUrZipythonrWru)rv)rrdr9r]splitextbasenamer-ryrzr{r|r}run_pathrrb)rmr main_namerlrrrrrs s    rscCs t|dS)z< Set sys.modules['__main__'] to module at main_path N)rs)rmrrrr%sr)NN)%r9rr}r{r;rrrcontextrr__all__r5rfrgr-r.lowerrxr]r0 exec_prefixrr r rr r r rrLr ryrHrrrsrrrrr s<        2&