o
    l¨Êhÿ  ã                	   @   s   d dl Z d dlZd dlZd dlZd dlmZ ddlmZmZ ddl	m
Z
mZ d dlmZmZ ejdd… dk r9eZejd	krDdd
lmZ g Zejd	kr`G dd„ deƒZe d¡ G dd„ deƒZedk�rd dlZe d¡Zejdeddd� ejdeddd� e  ¡ Z!e"ƒ Z#dZ$zuz=e  %e!j&d¡�(Z'de (¡ _)ze *e'¡Z+e ,e+¡ e *e'¡Z-W e (¡ `)ne (¡ `)w W d  ƒ n1 s½w   Y  e- .¡ Z$W n' e/yî   e0dƒ e0d 1e!j2¡ƒ e0dƒ d dl3Z3e0e3 4¡ ƒ e0dƒ Y nw W e'durøe' 5¡  e 6e$¡ dS e'du�re' 5¡  e 6e$¡ w dS )é    N)ÚBytesIOé   )Ú	reductionÚspawn)Úget_spawning_popenÚset_spawning_popen)ÚutilÚprocessé   ©é   r   Úwin32)Úresource_trackerc                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú_DupFdc                 C   s   t  |¡| _d S ©N)r   Ú_mk_inheritableÚfd©Úselfr   © r   ú`/var/www/html/env/lib/python3.10/site-packages/joblib/externals/loky/backend/popen_loky_posix.pyÚ__init__   s   z_DupFd.__init__c                 C   s   | j S r   )r   ©r   r   r   r   Údetach"   s   z_DupFd.detachN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s    r   ÚPopenc                   @   sp   e Zd ZdZeZdd„ Zejdk re	dd„ ƒZ
ndd„ Z
ejfdd	„Zddd„Zdd„ Zdd„ Zedd„ ƒZd
S )r   Úlokyc                 C   s.   t j ¡  t j ¡  d | _g | _|  |¡ d S r   )ÚsysÚstdoutÚflushÚstderrÚ
returncodeÚ_fdsÚ_launch)r   Úprocess_objr   r   r   r   /   s
   

zPopen.__init__)r   é   c                 C   s   t ƒ }|j |¡ t |¡S r   )r   r$   Úappendr   r   )Úclsr   Úpopenr   r   r   Úduplicate_for_child7   s   
zPopen.duplicate_for_childc                 C   s   | j  |¡ t |¡S r   )r$   r(   r   r   r   r   r   r   r+   >   s   
c                 C   s‚   | j d u r>	 zt | j|¡\}}W n
 ty   Y d S w 	 || jkr>t |¡r1t |¡ | _ | j S t |¡s8J ‚t |¡| _ | j S r   )	r#   ÚosÚwaitpidÚpidÚOSErrorÚWIFSIGNALEDÚWTERMSIGÚ	WIFEXITEDÚWEXITSTATUS)r   Úflagr.   Ústsr   r   r   ÚpollB   s   
ý

þz
Popen.pollNc                 C   sÒ   t jdk rAdd l}|d u r|  d¡S | ¡ | }d}	 |  ¡ }|d ur&	 |S || ¡  }|dkr3	 |S t|d |dƒ}| |¡ q| jd u rf|d urYddlm} || j	g|ƒsYd S |  |dkrct
j¡S d¡S | jS )	Nr   r   gü©ñÒMb@?r   r
   gš™™™™™©?)Úwaitg        )r   Úversion_infoÚtimer6   ÚminÚsleepr#   Úmultiprocessing.connectionr7   Úsentinelr,   ÚWNOHANG)r   Útimeoutr9   ÚdeadlineÚdelayÚresÚ	remainingr7   r   r   r   r7   U   s2   

ûþ
ø
z
Popen.waitc                 C   s^   | j d u r-zt | jtj¡ W d S  ty   Y d S  ty,   | jdd�d u r)‚ Y d S w d S )Ngš™™™™™¹?)r?   )	r#   r,   Úkillr.   ÚsignalÚSIGTERMÚProcessLookupErrorr/   r7   r   r   r   r   Ú	terminatep   s   
ÿÿûzPopen.terminatec                 C   sä  t j ¡ }tƒ }t| ƒ zt |jt|ddƒ¡}t	 
||¡ t	 
||¡ W td ƒ ntd ƒ w z¤t ¡ \}}t ¡ \}}tjg}	|	d| jg7 }	|	dt|jƒg7 }	|	dtt	 |¡ƒg7 }	t	 |¡ t	 |¡ | j |||g¡ ddlm}
 |
|	| j|jd�}t d	 ||	¡¡ || _d
}t||ƒs’d}t |d¡�}| t||ƒƒ ¡ W d   ƒ n1 s¬w   Y  || _W |d urÂt | tj |f¡ ||fD ]}|d urÑt  |¡ qÆd S |d urát | tj |f¡ ||fD ]}|d urðt  |¡ qåw )NÚinit_main_moduleTz-mú--process-nameú--piper   )Ú	fork_exec)Úenvz'launched python with pid {} and cmd:
{}Ú	getbufferÚgetvalueÚwb)!r   Ú_resource_trackerÚgetfdr   r   r   Úget_preparation_dataÚ_nameÚgetattrr   Údumpr,   Úpiper   Ú
executabler   ÚstrÚnamer   r$   ÚextendrL   rM   r   ÚdebugÚformatr=   ÚhasattrÚfdopenÚwriter.   ÚFinalizeÚclose)r   r&   Ú
tracker_fdÚfpÚ	prep_dataÚparent_rÚchild_wÚchild_rÚparent_wÚ
cmd_pythonrL   r.   ÚmethodÚfr   r   r   r   r%   z   sd   

þÿ

ÿ
ÿ
€þþ
€þzPopen._launchc                   C   s   dS )NTr   r   r   r   r   Úthread_is_spawning«   s   zPopen.thread_is_spawningr   )r   r   r   rk   r   ÚDupFdr   r   r8   Úclassmethodr+   r,   r>   r6   r7   rH   r%   Ústaticmethodrm   r   r   r   r   r   +   s    


1Ú__main__zCommand line parserrK   TzFile handle for the pipe)ÚtypeÚrequiredÚhelprJ   z Identifier for debugging purpose)rr   Údefaultrt   ÚrbzR

--------------------------------------------------------------------------------z{} failed with traceback: zP--------------------------------------------------------------------------------zQ
--------------------------------------------------------------------------------)7r,   r   rE   ÚpickleÚior   Ú r   r   Úcontextr   r   Úmultiprocessingr   r	   r8   r/   rG   Úplatformr   Ú__all__Úobjectr   r(   r   r   ÚargparseÚArgumentParserÚparserÚadd_argumentÚintrY   Ú
parse_argsÚargsÚdictÚinfoÚexitcoder_   rW   Úfrom_parentÚcurrent_processÚ_inheritingÚloadre   Úpreparer&   Ú
_bootstrapÚ	ExceptionÚprintr]   Úprocess_nameÚ	tracebackÚ
format_excrb   Úexitr   r   r   r   Ú<module>   sp   


 


ÿ
ÿ


ù	ú€
ýÝ