U
    ‰d½  ã                   @   s„   d dl mZ d dlZd dlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 d	gZG d
d„ deƒZG dd	„ d	ejƒZdS )é    )Úabsolute_importNé   )Úcontext)Ú
popen_fork)Ú	reduction)Úspawn)Úspawnv_passfdsÚPopenc                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú_DupFdc                 C   s
   || _ d S ©N©Úfd©Úselfr   © r   ú>/tmp/pip-unpacked-wheel-lulkwrw3/billiard/popen_spawn_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
   c                       s4   e Zd ZdZeZ‡ fdd„Zdd„ Zdd„ Z‡  Z	S )r	   r   c                    s   g | _ tt| ƒ |¡ d S r   )Ú_fdsÚsuperr	   r   )r   Úprocess_obj©Ú	__class__r   r   r   %   s    zPopen.__init__c                 C   s   | j  |¡ |S r   )r   Úappendr   r   r   r   Úduplicate_for_child)   s    zPopen.duplicate_for_childc              
   C   s6  dt jd< t ¡  ddlm} | ¡ }| j |¡ t 	|j
¡}t ¡ }t | ¡ zt ||¡ t ||¡ W 5 t d ¡ X d  } } }}	z~t  ¡ \}}t  ¡ \}}	tj||d}| j ||g¡ tt ¡ || jƒ| _|| _tj|	ddd}| | ¡ ¡ W 5 Q R X W 5 |||	fD ]}
|
d k	rt  |
¡ qX d S )	NÚ1ZMULTIPROCESSING_FORKING_DISABLEr   )Úsemaphore_tracker)Ú
tracker_fdZpipe_handleÚwbF)Úclosefd)ÚosÚenvironr   Z_Django_old_layout_hack__saveÚ r   Zgetfdr   r   Zget_preparation_dataÚ_nameÚioÚBytesIOr   Zset_spawning_popenr   ÚdumpÚcloseÚpipeZget_command_lineÚextendr   Úget_executableÚpidÚsentinelÚopenÚwriteÚgetvalue)r   r   r   r    Z	prep_dataÚfpZparent_rZchild_wZchild_rZparent_wr   ÚcmdÚfr   r   r   Ú_launch-   s>    

ÿ  ÿ
zPopen._launch)
r   r   r   Úmethodr
   ZDupFdr   r   r6   Ú__classcell__r   r   r   r   r	   !   s
   )Ú
__future__r   r'   r#   r%   r   r   r   r   Úcompatr   Ú__all__Úobjectr
   r	   r   r   r   r   Ú<module>   s   