Your IP : 18.116.24.148


Current Path : /opt/alt/python34/lib64/python3.4/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/multiprocessing/__pycache__/forkserver.cpython-34.pyc

�
e f!�@sdddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZddlmZddlm
Z
ddlmZd	d
ddgZd
Zejd�ZGdd�de�Zdddd�Zdd�Zdd�Zdd�Ze�ZejZejZejZejZdS)�N�)�
connection)�process)�	reduction)�semaphore_tracker)�spawn)�util�ensure_running�get_inherited_fds�connect_to_new_process�set_forkserver_preload��Qc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
ForkServercCs:d|_d|_d|_tj�|_dg|_dS)N�__main__)�_forkserver_address�_forkserver_alive_fd�_inherited_fds�	threadingZLock�_lock�_preload_modules)�self�r�?/opt/alt/python34/lib64/python3.4/multiprocessing/forkserver.py�__init__!s
			zForkServer.__init__cCs8tdd�|jD��s+td��n||_dS)z>Set list of module names to try to load in forkserver process.css!|]}t|�tkVqdS)N)�type�str)�.0�modrrr�	<genexpr>*sz4ForkServer.set_forkserver_preload.<locals>.<genexpr>z&module_names must be a list of stringsN)�allr�	TypeError)rZ
modules_namesrrrr(sz!ForkServer.set_forkserver_preloadcCs|jS)z�Return list of fds inherited from parent process.

        This returns None if the current process was not started by fork
        server.
        )r)rrrrr
.szForkServer.get_inherited_fdscCs|j�t|�dtkr/td��ntjtj���}|j|j�tj	�\}}tj	�\}}|||j
tj�g}||7}zJyt
j||�||fSWn%tj|�tj|��YnXWdtj|�tj|�XWdQXdS)a;Request forkserver to create a child process.

        Returns a pair of fds (status_r, data_w).  The calling process can read
        the child process's pid and (eventually) its returncode from status_r.
        The calling process should write to data_w the pickled preparation and
        process data.
        �ztoo many fdsN)r	�len�MAXFDS_TO_SEND�
ValueError�socket�AF_UNIXZconnectr�os�piperrZgetfdrZsendfds�close)r�fdsZclientZparent_r�child_w�child_rZparent_wZallfdsrrrr6s&




z!ForkServer.connect_to_new_processcs�|j��tj�|jdk	r'dSdd}|jr}ddh�tjd�}t�fdd�|j�D��}ni}t	j	t	j
��
}tjd	�}|j
|�tj|d
�|jd�tj�\}}z�yy|j�|g}||j�||j|f;}tj�}|gtj�}	|	d|g7}	tj||	|�}
Wntj|��YnXWdtj|�X||_||_WdQXWdQXdS)
z�Make sure that a fork server is running.

        This can be called from any process.  Note that usually a child
        process will just reuse the forkserver started by its parent, so
        ensure_running() will do nothing.
        Nz-from multiprocessing.forkserver import main; zmain(%d, %d, %r, **%r)�	main_path�sys_path�ignorec3s-|]#\}}|�kr||fVqdS)Nr)r�x�y)�desired_keysrrres	z,ForkServer.ensure_running.<locals>.<genexpr>r'i��dz-c)rrr	rrrZget_preparation_data�dict�itemsr&r'rZarbitrary_addressZbindr(�chmodZlistenr)�filenoZget_executablerZ_args_from_interpreter_flagsZspawnv_passfdsr*r)r�cmd�data�listenerZaddress�alive_rZalive_wZfds_to_passZexe�args�pidr)r3rr	Ss>

	(



	zForkServer.ensure_runningN)�__name__�
__module__�__qualname__rrr
rr	rrrrrs
rc
<Cs�|r�d|krQ|dk	rQdtj�_ztj|�Wdtj�`Xnx4|D])}yt|�WqXtk
r�YqXXqXWntjdk	r�y#tjj	�t
tj�t_Wq�t
tfk
r�Yq�Xntjtjtj�}tjtjd|���}tj���}|j�t_|j|tj�|j|tj�x]yx'dd�|j�D�}	|	rXPqXqXW||	kr�tj|d�dks�t�t�n||	ks�t�|j�d	��}
d}tj �d	krSzPyt!|
|||�Wn2t"k
r=tj#tj$��tj%j&�YnXWdtj'|�XnWdQXWqRt(k
rnYqRt
k
r�}z|j)t)j*kr��nWYdd}~XqRXqRWWdQXWdQXdS)
zRun forkserver.rNTr8cSsg|]\}}|j�qSr)Zfileobj)r�keyZeventsrrr�
<listcomp>�s	zmain.<locals>.<listcomp>r�r)+rZcurrent_processZ_inheritingrZimport_main_path�
__import__�ImportError�sys�stdinr*�openr(�devnull�OSErrorr%�signal�SIGCHLD�SIG_IGNr&r'�	selectorsZDefaultSelectorZgetsockname�_forkserverr�registerZ
EVENT_READZselect�read�AssertionError�
SystemExitZaccept�fork�
_serve_one�	Exception�
excepthook�exc_info�stderr�flush�_exit�InterruptedError�errnoZECONNABORTED)
Zlistener_fdr<Zpreloadr.r/�modname�handlerr;ZselectorZrfds�s�code�errr�main�s^


	

rdc
Cs�|j�tj|�tjtj|�tj|td�}|j�t|�tksbt�|^}}t	_
}t	_|tj
_t|tj��dtjkr�ddl}|j�ntj|�}	t||	�dS)Nr�randomr)r*r(rLrMrZrecvfdsr$r#rSrPrrrZ_semaphore_trackerZ_fd�write_unsigned�getpidrG�modulesreZseedr�_main)
rar;r<r`r+r-r,ZstfdrerbrrrrV�s



rVcCs�d}tj}xrt|�|kr�x:y tj||t|��}Wntk
r[Yq'XPq'W|svtd��n||7}qWtj|�dS)NrDzunexpected EOFr)�UNSIGNED_STRUCT�sizer#r(rRr]�EOFErrorZunpack)�fdr:Zlengthrarrr�
read_unsigned�s	 
rncCs~tj|�}xh|ryx0ytj||�}Wntk
rEYqXPqW|dkrftd��n||d�}qWdS)Nrzshould not get here)rjZpackr(�writer]�RuntimeError)rm�n�msg�nbytesrrrrf�s	
rf)r^r(rOrLr&ZstructrGr�rrrrrr�__all__r$ZStructrj�objectrrdrVrnrfrPr	r
rrrrrr�<module>s6		h> 				

?>