Your IP : 18.118.24.176


Current Path : /opt/alt/python35/lib64/python3.5/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/multiprocessing/__pycache__/forkserver.cpython-35.opt-2.pyc



���] �@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�	threading�Lock�_lock�_preload_modules)�self�r�//opt/alt/python35/lib64/python3.5/forkserver.py�__init__!s
			zForkServer.__init__cCs5tdd�|jD��s(td��||_dS)Ncss!|]}t|�tkVqdS)N)�type�str)�.0�modrrr�	<genexpr>*sz4ForkServer.set_forkserver_preload.<locals>.<genexpr>z&module_names must be a list of strings)�allr�	TypeError)rZ
modules_namesrrrr(sz!ForkServer.set_forkserver_preloadcCs|jS)N)r)rrrrr
.szForkServer.get_inherited_fdscCs
|j�t|�dtkr,td��tjtj���}|j|j�tj	�\}}tj	�\}}|||j
tj�g}||7}zJyt
j||�||fSWn%tj|�tj|��YnXWdtj|�tj|�XWdQRXdS)N�ztoo many fds)r	�len�MAXFDS_TO_SEND�
ValueError�socket�AF_UNIX�connectr�os�piperrZgetfdr�sendfds�close)r�fds�clientZparent_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	�|j�tj�\}}z�yy|j�|g}||j�||j|f;}tj�}|gtj�}	|	d
|g7}	tj||	|�}
Wntj|��YnXWdtj|�X||_||_WdQRXWdQRXdS)Nz-from multiprocessing.forkserver import main; zmain(%d, %d, %r, **%r)�	main_path�sys_path�ignorec3s-|]#\}}|�kr||fVqdS)Nr)r�x�y)�desired_keysrrr es	z,ForkServer.ensure_running.<locals>.<genexpr>r(i�z-c)rrr	rrrZget_preparation_data�dict�itemsr'r(r�arbitrary_address�bindr*�chmod�listenr+�filenoZget_executabler�_args_from_interpreter_flags�spawnv_passfdsr-r)r�cmd�data�listener�address�alive_rZalive_wZfds_to_passZexe�args�pidr)r7rr	Ss>

	(



	zForkServer.ensure_runningN)�__name__�
__module__�__qualname__rrr
rr	rrrrrs
rc4CsH|r�d|krN|dk	rNdtj�_ztj|�Wdtj�`Xx1|D])}yt|�WqUtk
r}YqUXqUWtj�t	j
t	jt	jt	j
i}dd�|j�D�}tjtjd|��f}tj��P}	|j�t_|	j|tj�|	j|tj�xy�x$dd�|	j�D�}
|
r+Pq+W||
krat�|j�d��}d	}tj�dkr�zPyt||||�Wn2tk
r�tj tj!��tj"j#�YnXWdtj$|�XWdQRXWq%t%k
r1}
z|
j&t&j'kr�WYdd}
~
Xq%Xq%WWdQRXWdQRXdS)
NrTcSs+i|]!\}}tj||�|�qSr)�signal)r�sig�valrrr�
<dictcomp>�s	zmain.<locals>.<dictcomp>r>cSsg|]\}}|j�qSr)�fileobj)r�key�eventsrrr�
<listcomp>�s	zmain.<locals>.<listcomp>rr)(r�current_processZ_inheritingrZimport_main_path�
__import__�ImportErrorr�_close_stdinrK�SIGCHLD�SIG_IGN�SIGINT�SIG_DFLr9r'r(�	selectors�DefaultSelector�getsockname�_forkserverr�register�
EVENT_READ�select�
SystemExit�acceptr*�fork�
_serve_one�	Exception�sys�
excepthook�exc_info�stderr�flush�_exit�OSError�errnoZECONNABORTED)Zlistener_fdrEZpreloadr2r3�modname�handlersZold_handlersrC�selectorZrfds�s�code�errr�main�sR


	
	
rucCs�|j�tj|�x*|j�D]\}}tj||�q$Wtj|td�}|j�|^}}t_}	t_	|	t
j_t
|tj��dtjkr�ddl}
|
j�tj|�}t
||�dS)Nr�randomr)r-r*r9rKr�recvfdsr%r^rrrZ_semaphore_trackerZ_fd�write_unsigned�getpidrg�modulesrv�seedr�_main)rrrCrErprLrMr.r1r0Zstfdrvrsrrrre�s



recCsqd}tj}xNt|�|kr_tj||t|��}|sRtd��||7}qWtj|�dS)N�zunexpected EOFr)�UNSIGNED_STRUCT�sizer$r*�read�EOFError�unpack)�fdrB�lengthrrrrr�
read_unsigned�s	r�cCsZtj|�}xD|rUtj||�}|dkrBtd��||d�}qWdS)Nrzshould not get here)r~�packr*�write�RuntimeError)r��n�msg�nbytesrrrrx�s	rx)rnr*r[rKr'�structrgr�rrrrrr�__all__r%�Structr~�objectrrurer�rxr^r	r
rrrrrr�<module>s6		h=!
				

?>