U
    e#                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZmZ ejdkrLdZ	dZ
n:d dlZd dlmZ ejdkoteeddZ	ej dZ
e
re jejdZnejZd	d
 Zdd ZdddZg ZdddZdd Zdd ZdS )    N)processutilwin32F)	duplicatefrozenzpythonservice.exez
python.exec                   C   s   t S )N)_python_exe r   r   d/var/www/html/assets/scripts/venv/lib/python3.8/site-packages/joblib/externals/loky/backend/spawn.pyget_executable!   s    r
   c                   C   s"   t t ddrttdd S )NZ_inheritingFa.              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.)getattrr   current_processRuntimeErrortextwrapdedentr   r   r   r	   _check_not_importing_main%   s    r   Tc           	      C   s  t   ttjtt j| tj	tj
t d}dd tjD |d< tjdk	rztj |d< tjjrztjjd }|jj|d< d	d
lm} |  d|ji|d< tjdkrt|j|d d< n|j|d d< tjdkrtjdkrdd
lm} |  |j|jd|d< |rtjd }zt|j dd}W n t!k
rD   d}Y nX |dk	rZ||d< nhtjdksrt"st#st|dd}|dk	rtj$|stj
dk	rtj%tj
|}tj&||d< |S )zDReturn info about parent needed by child to unpickle process object.)log_to_stderrauthkeynamesys_argvorig_dirdirc                 S   s   g | ]}|d kr|nt jqS ) )r   ORIGINAL_DIR).0pr   r   r	   
<listcomp>H   s     z(get_preparation_data.<locals>.<listcomp>sys_pathN	log_levelr   log_fmt   _resource_trackerpidtracker_argsr   fhfd)      posix)r%   r"   mp_tracker_args__main__r   init_main_from_name__file__init_main_from_path)'r   dictr   Z_log_to_stderrbytesr   r   r   sysargvr   osgetcwdpathZ_loggergetEffectiveLevelhandlers	formatter_fmtresource_trackerr!   Zensure_running_pidplatformmsvcrtZget_osfhandle_fdversion_infor    multiprocessing.resource_trackermodulesr   __spec__BaseExceptionWINEXE
WINSERVICEisabsjoinnormpath)	r   Zinit_main_moduledhr!   mp_resource_trackermain_moduleZmain_mod_name	main_pathr   r   r	   get_preparation_data;   sZ    


	






rM   c                 C   s  d| kr| d t  _d| kr,| d t  _d| krD| d rDt  d| kr^t | d  d| krddl}t j	d 
|| d  d| kr| d t_d	| kr| d	 t_d
| krt| d
  d| kr| d t _d| kr
ddlm} | d d |_| d d |_d| krrddlm} | d d |_tjdkrd| d d }t||d}t|tj|_n| d d |_d| krt| d  nd| krt| d  dS )z<Try to get current process ready to unpickle process object.r   r   r   r   r   r   Nr   r   r   r   r)   r    r%   r"   r#   r   r   r$   )Zsource_processr+   r-   )r   r   r   r   r   r   Z
get_loggersetLevelloggingr6   setFormatter	Formatterr0   r4   r1   r2   chdirr   r?   r!   r=   r:   r9   r;   r   r<   open_osfhandleO_RDONLY_fixup_main_from_name_fixup_main_from_path)dataZparent_sentinelrO   rJ   r!   handler   r   r	   prepare   sJ    






rY   c                 C   s~   t jd }| dks| dr d S t|jdd | kr6d S t| td}t	j
| ddd}|j| | t jd< t jd< d S )Nr*   z	.__main__r   __mp_main__T)run_name	alter_sys)r0   r@   endswithr   rA   old_main_modulesappendtypes
ModuleTyperunpy
run_module__dict__update)mod_namecurrent_mainrK   main_contentr   r   r	   rU      s    


  rU   c                 C   s   t jd }tjtj| d }|dkr.d S t|dd | krBd S t| t	
d}tj| dd}|j| | t jd< t jd< d S )Nr*   r   ipythonr,   rZ   )r[   )r0   r@   r2   r4   splitextbasenamer   r^   r_   r`   ra   rb   run_pathrd   re   )rL   rg   	main_namerK   rh   r   r   r	   rV      s    


rV   )T)N)r2   r0   rb   r   r`   multiprocessingr   r   r;   rC   rD   r<   Zmultiprocessing.reductionr   r   
executablelowerr]   r4   rF   exec_prefixr   r
   r   rM   r^   rY   rU   rV   r   r   r   r	   <module>	   s,   

P
;