AlkantarClanX12

Your IP : 18.225.175.230


Current Path : /usr/lib64/python3.6/multiprocessing/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/multiprocessing/__pycache__/pool.cpython-36.opt-2.pyc

3


 \�e�@s8ddgZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
mZdZdZ
dZej�Zdd	�Zd
d�ZGdd
�d
e�ZGdd�d�Zdd�ZGdd�de�Zdfddfdd�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�cCstt|��S)N)�list�map)�args�r�,/usr/lib64/python3.6/multiprocessing/pool.py�mapstar+srcCsttj|d|d��S)Nrr)r	�	itertools�starmap)rrrr
�starmapstar.src@seZdZdd�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
r5src@seZdZdd�Zdd�ZdS)�ExceptionWithTracebackcCs0tjt|�||�}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;srcCst|�|_|S)N)r�	__cause__)r rrrr
r!Ds
r!cs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�MaybeEncodingErrorcs.t|�|_t|�|_tt|�j|j|j�dS)N)�reprr �value�superr$r)rr r&)�	__class__rr
rPs

zMaybeEncodingError.__init__cCsd|j|jfS)Nz(Error sending result: '%s'. Reason: '%s')r&r )rrrr
rUszMaybeEncodingError.__str__cCsd|jj|fS)Nz<%s: %s>)r(r)rrrr
�__repr__YszMaybeEncodingError.__repr__)rrrrrr)�
__classcell__rr)r(r
r$Lsr$Fc'Cs�|j}|j}t|d�r*|jj�|jj�|dk	r:||�d}�xH|dksX|oT||k�r�y
|�}	Wn$ttfk
r�tj	d�PYnX|	dkr�tj	d�P|	\}
}}}
}yd||
|�f}WnBt
k
r�}z&|r�|tk	r�t||j
�}d|f}WYdd}~XnXy||
||f�WnRt
k
�rd}z4t||d�}tj	d|�||
|d|ff�WYdd}~XnXd}	}
}}}
}|d7}qBWtj	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





$rCcCs|�dS)Nr)Zexrrr
r5�sr5c@s2eZdZdZdd�Zddfddfdd�Zdd�Zd	d
�Zdd�Zd
d�Z	fifdd�Z
d<dd�Zd=dd�Zd>dd�Z
dd�Zd?dd�Zd@dd�Zfiddfdd�ZdAd d!�ZdBd"d#�Zed$d%��Zed&d'��Zed(d)��Zed*d+��Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zed4d5��Zed6d7��Zd8d9�Z d:d;�Z!dS)CrTcOs|jj||�S)N)�_ctx�Process)rrr?rrr
rE�szPool.ProcessNcCsn|pt�|_|j�tj�|_i|_t|_||_	||_
||_|dkrPtj
�pNd}|dkr`td��|dk	rzt|�rztd��||_g|_|j�tjtj|fd�|_d|j_t|j_|jj�tjtj|j|j|j|j|jfd�|_d|j_t|j_|jj�tjtj|j|j |jfd�|_!d|j!_t|j!_|j!j�t"j#||j$|j|j%|j|j|j|j|j!|jfdd�|_&dS)Nrz&Number of processes must be at least 1zinitializer must be a callable)�targetrT�)rZexitpriority)'rrD�
_setup_queues�queue�Queue�
_taskqueue�_cache�RUN�_state�_maxtasksperchild�_initializer�	_initargs�os�	cpu_count�
ValueError�callable�	TypeError�
_processes�_pool�_repopulate_pool�	threadingZThreadr�_handle_workers�_worker_handler�daemon�start�
_handle_tasks�
_quick_put�	_outqueue�
_task_handler�_handle_results�
_quick_get�_result_handlerrZFinalize�_terminate_pool�_inqueue�
_terminate)r�	processesr9r:Zmaxtasksperchild�contextrrr
r�sT




z
Pool.__init__cCsZd}xPttt|j���D]:}|j|}|jdk	rtjd|�|j�d}|j|=qW|S)NFzcleaning up worker %dT)�reversed�range�lenrX�exitcoderr3r)rZcleanedr=rCrrr
�_join_exited_workers�s

zPool._join_exited_workersc	Cs|xvt|jt|j��D]^}|jt|j|j|j|j	|j
|jfd�}|jj|�|j
jdd�|_
d|_|j�tjd�qWdS)N)rFrrEZ
PoolWorkerTzadded worker)rlrWrmrXrErCrgrarPrQrO�_wrap_exception�append�name�replacer]r^rr3)rr=�wrrr
rY�szPool._repopulate_poolcCs|j�r|j�dS)N)rorY)rrrr
�_maintain_pool�szPool._maintain_poolcCs4|jj�|_|jj�|_|jjj|_|jjj|_	dS)N)
rDZSimpleQueuergrar+�sendr`r0�recvrd)rrrr
rH�szPool._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)rzrr-)rr>r{r|rrr
rszPool.starmapcCs|j||t|||�S)N)rzr)rr>r{r|�callback�error_callbackrrr
�
starmap_asyncszPool.starmap_asyncccsny0d}x&t|�D]\}}||||fifVqWWn8tk
rh}z||dt|fifVWYdd}~XnXdS)Nr���)�	enumerater4r5)rZ
result_jobr>r{r=�xrArrr
�_guarded_task_generationszPool._guarded_task_generationrcCs�|jtkrtd��|dkrFt|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>)
rNrMrT�IMapIteratorrLrKr,r��_job�_set_lengthr�
_get_tasksr)rr>r{r|r@�task_batchesrrr
�imap's 




z	Pool.imapcCs�|jtkrtd��|dkrFt|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>)
rNrMrT�IMapUnorderedIteratorrLrKr,r�r�r�rr�r)rr>r{r|r@r�rrr
�imap_unorderedBs 




zPool.imap_unorderedcCsB|jtkrtd��t|j||�}|jj|jd|||fgdf�|S)NzPool not runningr)rNrMrT�ApplyResultrLrKr,r�)rr>rr?r}r~r@rrr
rx]s

zPool.apply_asynccCs|j||t|||�S)N)rzr)rr>r{r|r}r~rrr
�	map_asynchszPool.map_asyncc
Cs�|jtkrtd��t|d�s$t|�}|dkrTtt|�t|j�d�\}}|rT|d7}t|�dkrdd}tj	|||�}t
|j|t|�||d�}	|jj
|j|	j||�df�|	S)NzPool not running�__len__�rr)r~)rNrMrTr.r	�divmodrmrXrr��	MapResultrLrKr,r�r�)
rr>r{Zmapperr|r}r~Zextrar�r@rrr
rzps&

zPool._map_asynccCsTtj�}x0|jtks$|jr8|jtkr8|j�tjd�q
W|j	j
d�tjd�dS)Ng�������?zworker handler exiting)
rZ�current_threadrNrMrL�	TERMINATEru�time�sleeprKr,rr3)�pool�threadrrr
r[�szPool._handle_workersc
Csjtj�}x�t|jd�D]�\}}d}z�x�|D]�}|jr@tjd�Py||�Wq*tk
r�}	zD|dd�\}
}y||
j|d|	f�Wnt	k
r�YnXWYdd}	~	Xq*Xq*W|r�tjd�|r�|dnd}||d�wPWdd}}}
XqWtjd�y:tjd�|j
d�tjd�x|D]}|d��q&WWn tk
�rZtjd	�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�)rZr��iterr-rNrr3r4�_set�KeyErrorr,r2)
�	taskqueuer,r8r��cacher�ZtaskseqZ
set_lengthr;rAr<�idx�prrr
r_�sB







zPool._handle_taskscCs�tj�}x�y
|�}Wn"ttfk
r6tjd�dSX|jrJtjd�P|dkr^tjd�P|\}}}y||j||�Wntk
r�YnXd}}}q
Wx�|o�|jt	k�r:y
|�}Wn"ttfk
r�tjd�dSX|dkr�tjd�q�|\}}}y||j||�Wntk
�r*YnXd}}}q�Wt
|d��r�tjd�y,x&td�D]}|jj
��spP|��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 sentinelr0z"ensuring that outqueue is not full�
z7result handler exiting: len(cache)=%s, thread._state=%s)rZr�r2r1rr3rNr�r�r�r.rlr0�pollrm)r8r-r�r�r;r<r=�objrrr
rc�sZ









zPool._handle_resultsccs4t|�}x&ttj||��}|s"dS||fVq
WdS)N)r��tupler�islice)r>�it�sizer�rrr
r�szPool._get_taskscCstd��dS)Nz:pool objects cannot be passed between processes or pickled)�NotImplementedError)rrrr
r"szPool.__reduce__cCs&tjd�|jtkr"t|_t|j_dS)Nzclosing pool)rr3rNrM�CLOSEr\)rrrr
r/s

z
Pool.closecCs$tjd�t|_t|j_|j�dS)Nzterminating pool)rr3r�rNr\rh)rrrr
�	terminates
zPool.terminatecCsDtjd�|jj�|jj�|jj�x|jD]}|j�q0WdS)Nzjoining pool)rr3r\rrbrerX)rr�rrr
rs



z	Pool.joincCsDtjd�|jj�x*|j�r>|jj�r>|jj�tj	d�qWdS)Nz7removing tasks from inqueue until task handler finishedr)
rr3Z_rlock�acquire�is_aliver0r�rwr�r�)r7�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	�|o�t
|dd��r$tjd	�x,|D]$}	|	j
�r�tjd
|	j�|	j	�q�WdS)Nzfinalizing poolz&helping task handler/workers to finishzjoining worker handlerrr�zterminating workerszjoining task handlerzjoining result handlerzjoining pool workerszcleaning up worker %d)rr3r�rNr�rmr,rZr�rr.rnr�r��pid)
�clsr�r7r8r�Zworker_handlerr�Zresult_handlerr�r�rrr
rf1s6










zPool._terminate_poolcCs|S)Nr)rrrr
�	__enter___szPool.__enter__cCs|j�dS)N)r�)r�exc_typeZexc_valZexc_tbrrr
�__exit__bsz
Pool.__exit__)N)N)NNN)r)r)NNN)NNN)"rrrrprErrorYrurHryr
rrr�r�r�rxr�rz�staticmethodr[r_rcr�r"r/r�rr��classmethodrfr�r�rrrr
r�sD8








.<			.c@s@eZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�ZdS)r�cCs4tj�|_tt�|_||_||_||_|||j<dS)N)	rZZEvent�_event�next�job_counterr�rL�	_callback�_error_callback)rr�r}r~rrr
rks

zApplyResult.__init__cCs
|jj�S)N)r�Zis_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.getcCsV|\|_|_|jr$|jr$|j|j�|jr>|jr>|j|j�|jj�|j|j=dS)N)r�r�r�r�r��setrLr�)rr=r�rrr
r��s
zApplyResult._set)N)N)	rrrrr�r�r�r-r�rrrr
r�is

	r�c@seZdZdd�Zdd�ZdS)r�cCsftj||||d�d|_dg||_||_|dkrLd|_|jj�||j=n||t	||�|_dS)N)r~Tr)
r�rr�r��
_chunksize�_number_leftr�r�r��bool)rr�r|�lengthr}r~rrr
r�s


zMapResult.__init__cCs�|jd8_|\}}|rp|jrp||j||j|d|j�<|jdkr�|jrZ|j|j�|j|j=|jj�nH|r�|jr�d|_||_|jdkr�|j	r�|j	|j�|j|j=|jj�dS)NrrF)
r�r�r�r�r�rLr�r�r�r�)rr=Zsuccess_result�successr@rrr
r��s"




zMapResult._setN)rrrrr�rrrr
r��s
r�c@s:eZdZdd�Zdd�Zddd�ZeZdd	�Zd
d�ZdS)
r�cCsJtjtj��|_tt�|_||_tj	�|_
d|_d|_i|_
|||j<dS)Nr)rZZ	ConditionZLock�_condr�r�r�rL�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�}Wnhtk
r~|j|jkr6t�|jj|�y|jj�}Wn(tk
rx|j|jkrpt�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|krr|jj|�|jd7_x8|j|jkrd|jj|j�}|jj|�|jd7_q.W|jj�n
||j|<|j|jkr�|j|j	=WdQRXdS)Nr)
r�r�r�rqr��pop�notifyr�rLr�)rr=r�rrr
r��s

zIMapIterator._setc	Cs<|j�,||_|j|jkr.|jj�|j|j=WdQRXdS)N)r�r�r�r�rLr�)rr�rrr
r��s

zIMapIterator._set_length)N)	rrrrr�r��__next__r�r�rrrr
r��s

r�c@seZdZdd�ZdS)r�c
CsP|j�@|jj|�|jd7_|jj�|j|jkrB|j|j=WdQRXdS)Nr)r�r�rqr�r�r�rLr�)rr=r�rrr
r�s
zIMapUnorderedIterator._setN)rrrr�rrrr
r��sr�c@s@eZdZdZedd��Zddffdd�Zdd�Zed	d
��ZdS)rFcOsddlm}|||�S)Nr)rE)ZdummyrE)rr?rErrr
rEszThreadPool.ProcessNcCstj||||�dS)N)rr)rrir9r:rrr
rszThreadPool.__init__cCs,tj�|_tj�|_|jj|_|jj|_dS)N)rIrJrgrar,r`r-rd)rrrr
rHs


zThreadPool._setup_queuesc
Cs<|j�,|jj�|jjdg|�|jj�WdQRXdS)N)Z	not_emptyrI�clear�extendZ
notify_all)r7r�r�rrr
r�s
zThreadPool._help_stuff_finish)	rrrrpr�rErrHr�rrrr
rs
)"�__all__rZrIrr�rRr�rrrrrrMr�r��countr�rrr4rrr!r$rCr5�objectrr�ZAsyncResultr�r�r�rrrrr
�<module>
s@	*\&)@