AlkantarClanX12

Your IP : 18.224.56.127


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



���]�d�@s�ddgZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
mZdZdZ
dZej�Zdd	�Zd
d�ZGdd
�d
e�ZGdd�d�Zdd�ZGdd�de�Zdfdddd�Zdd�ZGdd�de�ZGdd�de�ZeZGdd�de�ZGdd�de�ZGd d!�d!e�Z Gd"d�de�Z!dS)#�Pool�
ThreadPool�N�)�util)�get_context�TimeoutError�cCstt|��S)N)�list�map)�args�r�)/opt/alt/python35/lib64/python3.5/pool.py�mapstar+srcCsttj|d|d��S)Nrr)r	�	itertools�starmap)rrrr
�starmapstar.src@s(eZdZdd�Zdd�ZdS)�RemoteTracebackcCs
||_dS)N)�tb)�selfrrrr
�__init__6szRemoteTraceback.__init__cCs|jS)N)r)rrrr
�__str__8szRemoteTraceback.__str__N)�__name__�
__module__�__qualname__rrrrrr
r5src@s(eZdZdd�Zdd�ZdS)�ExceptionWithTracebackcCsDtjt|�||�}dj|�}||_d||_dS)N�z

"""
%s""")�	traceback�format_exception�type�join�excr)rr rrrr
r<s	zExceptionWithTraceback.__init__cCst|j|jffS)N)�rebuild_excr r)rrrr
�
__reduce__Asz!ExceptionWithTraceback.__reduce__N)rrrrr"rrrr
r;srcCst|�|_|S)N)r�	__cause__)r rrrr
r!Dsr!cs:eZdZ�fdd�Zdd�Zdd�Z�S)�MaybeEncodingErrorcsAt|�|_t|�|_tt|�j|j|j�dS)N)�reprr �value�superr$r)rr r&)�	__class__rr
rPszMaybeEncodingError.__init__cCsd|j|jfS)Nz(Error sending result: '%s'. Reason: '%s')r&r )rrrr
rUs	zMaybeEncodingError.__str__cCsd|jj|fS)Nz<%s: %s>)r(r)rrrr
�__repr__YszMaybeEncodingError.__repr__)rrrrrr)rr)r(r
r$Lsr$Fc'Cs|j}|j}t|d�r;|jj�|jj�|dk	rQ||�d}x�|dksx|r�||kr�y
|�}	Wn&ttfk
r�tj	d�PYnX|	dkr�tj	d�P|	\}
}}}
}yd||
|�f}WnUt
k
rM}z5|r/|tk	r/t||j
�}d|f}WYdd}~XnXy||
||f�Wnbt
k
r�}zBt||d�}tj	d|�||
|d|ff�WYdd}~XnXd}	}
}}}
}|d7}qZWtj	d	|�dS)
N�_writerrz)worker got EOFError or OSError -- exitingzworker got sentinel -- exitingTFrz0Possible encoding error while sending result: %szworker exiting after %d tasks)�put�get�hasattrr*�close�_reader�EOFError�OSErrorr�debug�	Exception�_helper_reraises_exceptionr�
__traceback__r$)�inqueue�outqueue�initializer�initargsZmaxtasksZwrap_exceptionr+r,Z	completed�task�job�i�funcr�kwds�result�e�wrappedrrr
�worker]sD		


!


	,rBcCs
|�dS)Nr)�exrrr
r4�sr4c@s�eZdZdZdd�Zddfdddd�Zdd�Zd	d
�Zdd�Zd
d�Z	fidd�Z
ddd�Zddd�Zddddd�Z
dd�Zddd�Zddd�Zfidddd�Zdddd d!�Zdddd"d#�Zed$d%��Zed&d'��Zed(d)��Zed*d+��Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zed4d5��Zed6d7��Zd8d9�Z d:d;�Z!dS)<rTcOs|jj||�S)N)�_ctx�Process)rrr>rrr
rE�szPool.ProcessNcCs#|pt�|_|j�tj�|_i|_t|_||_	||_
||_|dkrvtj
�psd}|dkr�td��|dk	r�t|�r�td��||_g|_|j�tjdtjd|f�|_d|j_t|j_|jj�tjdtjd|j|j|j|j|jf�|_d|j_t|j_|jj�tjdtjd|j|j |jf�|_!d|j!_t|j!_|j!j�t"j#||j$d|j|j%|j|j|j|j|j!|jfdd�|_&dS)	Nrz&Number of processes must be at least 1zinitializer must be a callable�targetrT�exitpriority�)'rrD�
_setup_queues�queue�Queue�
_taskqueue�_cache�RUN�_state�_maxtasksperchild�_initializer�	_initargs�os�	cpu_count�
ValueError�callable�	TypeError�
_processes�_pool�_repopulate_pool�	threading�Threadr�_handle_workers�_worker_handler�daemon�start�
_handle_tasks�
_quick_put�	_outqueue�
_task_handler�_handle_results�
_quick_get�_result_handlerr�Finalize�_terminate_pool�_inqueue�
_terminate)r�	processesr8r9�maxtasksperchild�contextrrr
r�sT
							
		
		
		
z
Pool.__init__cCswd}xjttt|j���D]M}|j|}|jdk	r"tjd|�|j�d}|j|=q"W|S)NFzcleaning up worker %dT)�reversed�range�lenrY�exitcoderr2r)rZcleanedr<rBrrr
�_join_exited_workers�s"

zPool._join_exited_workerscCs�x�t|jt|j��D]�}|jdtd|j|j|j|j	|j
|jf�}|jj|�|j
jdd�|_
d|_|j�tjd�qWdS)NrFrrEZ
PoolWorkerTzadded worker)rprXrqrYrErBrjrcrQrRrP�_wrap_exception�append�name�replacer_r`rr2)rr<�wrrr
rZ�s#	
zPool._repopulate_poolcCs|j�r|j�dS)N)rsrZ)rrrr
�_maintain_pool�szPool._maintain_poolcCsL|jj�|_|jj�|_|jjj|_|jjj|_	dS)N)
rD�SimpleQueuerjrcr*�sendrbr/�recvrf)rrrr
rI�szPool._setup_queuescCs|j|||�j�S)N)�apply_asyncr,)rr=rr>rrr
�apply�sz
Pool.applycCs|j||t|�j�S)N)�
_map_asyncrr,)rr=�iterable�	chunksizerrr
r
szPool.mapcCs|j||t|�j�S)N)rrr,)rr=r�r�rrr
rszPool.starmapcCs|j||t|||�S)N)rr)rr=r�r��callback�error_callbackrrr
�
starmap_asyncszPool.starmap_asyncccs�y>d}x1t|�D]#\}}||||fifVqWWn@tk
r�}z ||dt|fifVWYdd}~XnXdS)Nr���)�	enumerater3r4)rZ
result_jobr=r�r<�xr@rrr
�_guarded_task_generationszPool._guarded_task_generationrcCs�|jtkrtd��|dkret|j�}|jj|j|j||�|j	f�|St
j|||�}t|j�}|jj|j|jt|�|j	f�dd�|D�SdS)NzPool not runningrcss"|]}|D]}|Vq
qdS)Nr)�.0�chunk�itemrrr
�	<genexpr>@szPool.imap.<locals>.<genexpr>)
rOrNrU�IMapIteratorrMrLr+r��_job�_set_lengthr�
_get_tasksr)rr=r�r�r?�task_batchesrrr
�imap's 	
	
z	Pool.imapcCs�|jtkrtd��|dkret|j�}|jj|j|j||�|j	f�|St
j|||�}t|j�}|jj|j|jt|�|j	f�dd�|D�SdS)NzPool not runningrcss"|]}|D]}|Vq
qdS)Nr)r�r�r�rrr
r�[sz&Pool.imap_unordered.<locals>.<genexpr>)
rOrNrU�IMapUnorderedIteratorrMrLr+r�r�r�rr�r)rr=r�r�r?r�rrr
�imap_unorderedBs 	
	
zPool.imap_unorderedcCs_|jtkrtd��t|j||�}|jj|jd|||fgdf�|S)NzPool not runningr)rOrNrU�ApplyResultrMrLr+r�)rr=rr>r�r�r?rrr
r}]s
+zPool.apply_asynccCs|j||t|||�S)N)rr)rr=r�r�r�r�rrr
�	map_asynchszPool.map_asyncc
Cs�|jtkrtd��t|d�s6t|�}|dkrztt|�t|j�d�\}}|rz|d7}t|�dkr�d}tj	|||�}t
|j|t|�|d|�}	|jj
|j|	j||�df�|	S)NzPool not running�__len__�rrr�)rOrNrUr-r	�divmodrqrYrr��	MapResultrMrLr+r�r�)
rr=r�Zmapperr�r�r��extrar�r?rrr
rps&(
		
zPool._map_asynccCsrtj�}xB|jtks6|jrP|jtkrP|j�tjd�qW|j	j
d�tjd�dS)Ng�������?zworker handler exiting)
r[�current_threadrOrNrM�	TERMINATEry�time�sleeprLr+rr2)�pool�threadrrr
r]�s*
zPool._handle_workersc
Cs�tj�}x+t|jd�D]
\}}d}z�x�|D]�}|jrXtjd�Py||�Wq;tk
r�}	zN|dd�\}
}y||
j|d|	f�Wnt	k
r�YnXWYdd}	~	Xq;Xq;W|rtjd�|r�|dnd}||d�wPWdd}}}
XqWtjd�yFtjd�|j
d�tjd�x|D]}|d�qkWWntk
r�tjd	�YnXtjd
�dS)Nz'task handler found thread._state != RUNrFzdoing set_length()rztask handler got sentinelz/task handler sending sentinel to result handlerz(task handler sending sentinel to workersz/task handler got OSError when sending sentinelsztask handler exitingr�)r[r��iterr,rOrr2r3�_set�KeyErrorr+r1)
�	taskqueuer+r7r��cacher�ZtaskseqZ
set_lengthr:r@r;�idx�prrr
ra�sB
	








zPool._handle_taskscCstj�}x�y
|�}Wn)ttfk
rGtjd�dSYnX|jr_tjd�P|dkrytjd�P|\}}}y||j||�Wntk
r�YnXd}}}qWx�|r�|jt	kr�y
|�}Wn)ttfk
rtjd�dSYnX|dkr4tjd�q�|\}}}y||j||�Wntk
roYnXd}}}q�Wt
|d�r�tjd�y2x+td�D]}|jj
�s�P|�q�WWnttfk
r�YnXtjdt|�|j�dS)	Nz.result handler got EOFError/OSError -- exitingz,result handler found thread._state=TERMINATEzresult handler got sentinelz&result handler ignoring extra sentinelr/z"ensuring that outqueue is not full�
z7result handler exiting: len(cache)=%s, thread._state=%s)r[r�r1r0rr2rOr�r�r�r-rpr/�pollrq)r7r,r�r�r:r;r<�objrrr
re�sZ

		




	


	zPool._handle_resultsccsDt|�}x1ttj||��}|s1dS||fVqWdS)N)r��tupler�islice)r=�it�sizer�rrr
r�szPool._get_taskscCstd��dS)Nz:pool objects cannot be passed between processes or pickled)�NotImplementedError)rrrr
r"szPool.__reduce__cCs5tjd�|jtkr1t|_t|j_dS)Nzclosing pool)rr2rOrN�CLOSEr^)rrrr
r.s
	z
Pool.closecCs0tjd�t|_t|j_|j�dS)Nzterminating pool)rr2r�rOr^rk)rrrr
�	terminates
	zPool.terminatecCsVtjd�|jj�|jj�|jj�x|jD]}|j�q>WdS)Nzjoining pool)rr2r^rrdrgrY)rr�rrr
rs



z	Pool.joincCsZtjd�|jj�x9|j�rU|jj�rU|jj�tj	d�qWdS)Nz7removing tasks from inqueue until task handler finishedr)
rr2Z_rlock�acquire�is_aliver/r�r|r�r�)r6�task_handlerr�rrr
�_help_stuff_finish(s



zPool._help_stuff_finishc	
Cs�tjd�t|_t|_tjd�|j||t|��t|_|jd�tjd�tj�|k	r�|j	�|r�t
|dd�r�tjd�x'|D]}	|	jdkr�|	j�q�Wtjd�tj�|k	r�|j	�tjd�tj�|k	r&|j	�|r�t
|dd�r�tjd	�x8|D]0}	|	j
�rStjd
|	j�|	j	�qSWdS)Nzfinalizing poolz&helping task handler/workers to finishzjoining worker handlerrr�zterminating workerszjoining task handlerzjoining result handlerzjoining pool workerszcleaning up worker %d)rr2r�rOr�rqr+r[r�rr-rrr�r��pid)
�clsr�r6r7r�Zworker_handlerr�Zresult_handlerr�r�rrr
ri1s6
		
	










zPool._terminate_poolcCs|S)Nr)rrrr
�	__enter___szPool.__enter__cCs|j�dS)N)r�)r�exc_type�exc_val�exc_tbrrr
�__exit__bsz
Pool.__exit__)"rrrrtrErrsrZryrIr~r
rr�r�r�r�r}r�r�staticmethodr]rarer�r"r.r�rr��classmethodrir�r�rrrr
r�sD	8	

.<			.c@s^eZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�ZdS)r�cCsJtj�|_tt�|_||_||_||_|||j<dS)N)	r[�Event�_event�next�job_counterr�rM�	_callback�_error_callback)rr�r�r�rrr
rks			zApplyResult.__init__cCs
|jj�S)N)r��is_set)rrrr
�readysszApplyResult.readycCs|jS)N)�_success)rrrr
�
successfulvszApplyResult.successfulNcCs|jj|�dS)N)r��wait)r�timeoutrrr
r�zszApplyResult.waitcCs<|j|�|j�st�|jr/|jS|j�dS)N)r�r�rr��_value)rr�rrr
r,}s
	zApplyResult.getcCsu|\|_|_|jr4|jr4|j|j�|jrW|jrW|j|j�|jj�|j|j=dS)N)r�r�r�r�r��setrMr�)rr<r�rrr
r��s
zApplyResult._set)	rrrrr�r�r�r,r�rrrr
r�is	r�c@s(eZdZdd�Zdd�ZdS)r�cCs�tj|||d|�d|_dg||_||_|dkrjd|_|jj�||j=n||t	||�|_dS)Nr�Tr)
r�rr�r��
_chunksize�_number_leftr�r�r��bool)rr�r��lengthr�r�rrr
r�s			

zMapResult.__init__cCs�|\}}|r�||j||j|d|j�<|jd8_|jdkr�|jrn|j|j�|j|j=|jj�nEd|_||_|j	r�|j	|j�|j|j=|jj�dS)NrrF)
r�r�r�r�rMr�r�r�r�r�)rr<Zsuccess_result�successr?rrr
r��s%	
			
zMapResult._setN)rrrrr�rrrr
r��s
r�c@sUeZdZdd�Zdd�Zddd�ZeZdd	�Zd
d�ZdS)r�cCsktjtj��|_tt�|_||_tj	�|_
d|_d|_i|_
|||j<dS)Nr)r[�	Condition�Lock�_condr�r�r�rM�collections�deque�_items�_index�_length�	_unsorted)rr�rrr
r�s				zIMapIterator.__init__cCs|S)Nr)rrrr
�__iter__�szIMapIterator.__iter__NcCs�|j��y|jj�}Wn�tk
r�|j|jkrEt�|jj|�y|jj�}Wn0tk
r�|j|jkr�t�t�YnXYnXWdQRX|\}}|r�|S|�dS)N)	r�r��popleft�
IndexErrorr�r��
StopIterationr�r)rr�r�r�r&rrr
r��s"


zIMapIterator.nextc
Cs�|j��|j|kr�|jj|�|jd7_xJ|j|jkr�|jj|j�}|jj|�|jd7_q;W|jj�n
||j|<|j|jkr�|j|j	=WdQRXdS)Nr)
r�r�r�rur��pop�notifyr�rMr�)rr<r�rrr
r��s

zIMapIterator._setc	CsJ|j�:||_|j|jkr?|jj�|j|j=WdQRXdS)N)r�r�r�r�rMr�)rr�rrr
r��s

	
zIMapIterator._set_length)	rrrrr�r��__next__r�r�rrrr
r��s
r�c@seZdZdd�ZdS)r�c
Cs`|j�P|jj|�|jd7_|jj�|j|jkrU|j|j=WdQRXdS)Nr)r�r�rur�r�r�rMr�)rr<r�rrr
r��s

zIMapUnorderedIterator._setN)rrrr�rrrr
r��sr�c@s[eZdZdZedd��Zddfdd�Zdd�Zed	d
��ZdS)rFcOsddlm}|||�S)Nr)rE)�dummyrE)rr>rErrr
rEszThreadPool.ProcessNcCstj||||�dS)N)rr)rrlr8r9rrr
rszThreadPool.__init__cCs@tj�|_tj�|_|jj|_|jj|_dS)N)rJrKrjrcr+rbr,rf)rrrr
rIszThreadPool._setup_queuesc
CsF|j�6|jj�|jjdg|�|jj�WdQRXdS)N)�	not_emptyrJ�clear�extend�
notify_all)r6r�r�rrr
r�s

zThreadPool._help_stuff_finish)	rrrrtr�rErrIr�rrrr
rs
)"�__all__r[rJrr�rSr�rrrrrrNr�r��countr�rrr3rrr!r$rBr4�objectrr�ZAsyncResultr�r�r�rrrrr
�<module>
s<		*��&%@