f _P$c@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)Zlen)argvrrr is_forking4srcCshttjrdi}tjddD]0}|d\}}|dkr@d||<qt|||<qtdi|tdS)zE Run code for process object if this in not the main process rNz=ZNoner)rsysrZsplitZint spawn_mainexit)kwdsZargnameZvaluerrrr>s  rcKsdttddr(tjdgdd|DSd}|ddd |D;}t}tg|d |dgS) zJ Returns prefix of command line used for spawning a child process rFrcSsg|] }d|qS)%s=%rrZ.0ZitemrrrZ Tz$get_command_line..zWr z#get_command_line..z-cN)getattrr executableZitemsjoinrZ_args_from_interpreter_flagsr)rZprogZoptsrrrr 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 duplicateZopen_osfhandleosZO_RDONLYr%Z_resource_trackerZ_fdZduprr) Z pipe_handleZ parent_pidZ tracker_fdr'r(r$Z new_handlefdparent_sentinelr%Zexitcoderrrr\s*     rc Cs|tj|dddR}dt_z,tj|}t|tj|}Wt`n t`0Wdn1sh0Y| |S)NZrbT)Zclosefd) r)Zfdopenrcurrent_process _inheritingrZpickleZloadprepareZ _bootstrap)r+r,Z from_parentZpreparation_dataZselfrrrrxs  2rcCsttddrtddS)Nr.Fa 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-Z RuntimeErrorrrrr_check_not_importing_mainsr0cCstttjtjd}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*)rsys_pathsys_argvorig_dirdir start_method__main__rinit_main_from_namer__file__init_main_from_path)r0ZdictrZ_log_to_stderrrr-r2Z_loggerZgetEffectiveLevelrpathZcopyZindexZ ValueError ORIGINAL_DIRupdaterr)Zgetcwdrmodulesr!__spec__r&WINEXE WINSERVICEZisabsr#Znormpath)rZdr4Zi 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 rr2r1r3r4r5r7r6r8T)Zforcer:r<N)rr-rr2rr1Z get_loggerZsetLevelrr=rr)Zchdirr>r_fixup_main_from_name_fixup_main_from_path)Zdatarrrr/s,   r/cCs~tjd}|dks|dr dSt|jdd|kr6dSt|td}t j |ddd}|j ||tjd<tjd<dS)Nr9z .__main__r __mp_main__T)run_nameZ alter_sys) rr@endswithr!rAold_main_modulesappendtypes ModuleTyperunpyZ run_module__dict__r?)Zmod_name current_mainrD main_contentrrrrFs    rFcCstjd}tjtj|d}|dkr.dSt|dd|krBdSt|t d}t j |dd}|j ||tjd<tjd<dS)Nr9rZipythonr;rH)rI)rr@r)r=ZsplitextZbasenamer!rKrLrMrNrOZrun_pathrPr?)rErQZ main_namerDrRrrrrG s    rGcCs t|dS)z< Set sys.modules['__main__'] to module at main_path N)rG)rErrrr %sr )NN)%r)rrOrMr*rrrZcontextrrZ__all__r&rBrCr!r"ZlowerrJr=r#Z exec_prefixrr r rrr rrr0r rKr/rFrGr rrrrZ s<        2&