AlkantarClanX12

Your IP : 18.224.73.124


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

U

e5d�~�@sdddgZddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddl
mZm
Z
ddlmZd	Zd
ZdZdZe��Zd
d�Zdd�ZGdd�de�ZGdd�d�Zdd�ZGdd�de�Zd+dd�Zdd�ZGdd �d e�Z Gd!d�de!�Z"Gd"d#�d#e!�Z#e#Z$Gd$d%�d%e#�Z%Gd&d'�d'e!�Z&Gd(d)�d)e&�Z'Gd*d�de"�Z(dS),�Pool�
ThreadPool�N)�Empty�)�util)�get_context�TimeoutError)�wait�INIT�RUN�CLOSE�	TERMINATEcCstt|��S�N)�list�map��args�r�,/usr/lib64/python3.8/multiprocessing/pool.py�mapstar/srcCstt�|d|d��S)Nrr)r�	itertools�starmaprrrr�starmapstar2src@seZdZdd�Zdd�ZdS)�RemoteTracebackcCs
||_dSr��tb)�selfrrrr�__init__:szRemoteTraceback.__init__cCs|jSrr�rrrr�__str__<szRemoteTraceback.__str__N)�__name__�
__module__�__qualname__rrrrrrr9src@seZdZdd�Zdd�ZdS)�ExceptionWithTracebackcCs0t�t|�||�}d�|�}||_d||_dS)N�z

"""
%s""")�	traceback�format_exception�type�join�excr)rr)rrrrr@s
zExceptionWithTraceback.__init__cCst|j|jffSr)�rebuild_excr)rrrrr�
__reduce__Esz!ExceptionWithTraceback.__reduce__N)r r!r"rr+rrrrr#?sr#cCst|�|_|Sr)r�	__cause__)r)rrrrr*Hs
r*cs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�MaybeEncodingErrorcs.t|�|_t|�|_tt|��|j|j�dSr)�reprr)�value�superr-r)rr)r/��	__class__rrrTs

zMaybeEncodingError.__init__cCsd|j|jfS)Nz(Error sending result: '%s'. Reason: '%s')r/r)rrrrrYs�zMaybeEncodingError.__str__cCsd|jj|fS)Nz<%s: %s>)r2r rrrr�__repr__]szMaybeEncodingError.__repr__)r r!r"rrr3�
__classcell__rrr1rr-Psr-rFc
Cs�|dk	r(t|t�r|dks(td�|���|j}|j}t|d�rR|j��|j	��|dk	rb||�d}|dks~|�r�||k�r�z
|�}	Wn(t
tfk
r�t�
d�Y�q�YnX|	dkr�t�
d��q�|	\}
}}}
}zd||
|�f}WnHtk
�r0}z(|�r|tk	�rt||j�}d|f}W5d}~XYnXz||
||f�WnRtk
�r�}z2t||d�}t�
d	|�||
|d|ff�W5d}~XYnXd}	}
}}}
}|d7}qft�
d
|�dS)NrzMaxtasks {!r} is not valid�_writerrz)worker got EOFError or OSError -- exitingzworker got sentinel -- exitingTFz0Possible encoding error while sending result: %szworker exiting after %d tasks)�
isinstance�int�AssertionError�format�put�get�hasattrr5�close�_reader�EOFError�OSErrorr�debug�	Exception�_helper_reraises_exceptionr#�
__traceback__r-)�inqueue�outqueue�initializer�initargsZmaxtasks�wrap_exceptionr:r;Z	completed�task�job�i�funcr�kwds�result�e�wrappedrrr�workerasN�





�$
rRcCs|�dSrr)ZexrrrrC�srCcs.eZdZdd��fdd�
Z�fdd�Z�ZS)�
_PoolCacheN��notifiercs||_t�j||�dSr)rUr0r)rrUrrNr1rrr�sz_PoolCache.__init__cs t��|�|s|j�d�dSr)r0�__delitem__rUr:)r�itemr1rrrV�sz_PoolCache.__delitem__)r r!r"rrVr4rrr1rrS�srSc@s�eZdZdZedd��ZdKdd�Zeje	fdd	�Z
d
d�Zdd
�Zedd��Z
edd��Zdd�Zedd��Zedd��Zdd�Zdd�Zdifdd�ZdLdd�ZdMd d!�ZdNd"d#�Zd$d%�ZdOd'd(�ZdPd)d*�Zdiddfd+d,�ZdQd-d.�ZdRd/d0�ZedSd1d2��Zed3d4��Z ed5d6��Z!ed7d8��Z"ed9d:��Z#d;d<�Z$d=d>�Z%d?d@�Z&dAdB�Z'edCdD��Z(edEdF��Z)dGdH�Z*dIdJ�Z+dS)TrTcOs|j||�Sr��Process)�ctxrrNrrrrY�szPool.ProcessNrcCsg|_t|_|pt�|_|��t��|_|j��|_	t
|j	d�|_||_||_
||_|dkrjt��phd}|dkrztd��|dk	r�t|�s�td��||_z|��WnHtk
r�|jD]}|jdkr�|��q�|jD]}|��q؂YnX|��}tjtj|j|j|j|j|j|j|j |j!|j
|j|j|j"||j	fd�|_#d|j#_$t%|j#_|j#�&�tjtj'|j|j(|j!|j|jfd�|_)d|j)_$t%|j)_|j)�&�tjtj*|j!|j+|jfd�|_,d|j,_$t%|j,_|j,�&�t-j.||j/|j|j |j!|j|j	|j#|j)|j,|jf	dd�|_0t%|_dS)	NrTrz&Number of processes must be at least 1zinitializer must be a callable��targetrT�)rZexitpriority)1�_poolr
�_stater�_ctx�
_setup_queues�queue�SimpleQueue�
_taskqueue�_change_notifierrS�_cache�_maxtasksperchild�_initializer�	_initargs�os�	cpu_count�
ValueError�callable�	TypeError�
_processes�_repopulate_poolrB�exitcode�	terminater(�_get_sentinels�	threadingZThreadr�_handle_workersrY�_inqueue�	_outqueue�_wrap_exception�_worker_handler�daemonr�start�
_handle_tasks�
_quick_put�
_task_handler�_handle_results�
_quick_get�_result_handlerrZFinalize�_terminate_pool�
_terminate)r�	processesrGrH�maxtasksperchild�context�p�	sentinelsrrrr�s�





��
��
�
��z
Pool.__init__cCs>|j|kr:|d|��t|d�t|dd�dk	r:|j�d�dS)Nz&unclosed running multiprocessing pool )�sourcere)r_�ResourceWarning�getattrrer:)rZ_warnrrrr�__del__s

�zPool.__del__c	Cs0|j}d|j�d|j�d|j�dt|j��d�	S)N�<�.z state=z pool_size=�>)r2r!r"r_�lenr^)r�clsrrrr3sz
Pool.__repr__cCs|jjg}|jjg}||�Sr)rwr>re)rZtask_queue_sentinelsZself_notifier_sentinelsrrrrss

zPool._get_sentinelscCsdd�|D�S)NcSsg|]}t|d�r|j�qS)�sentinel)r<r�)�.0rRrrr�
<listcomp>s
�z.Pool._get_worker_sentinels.<locals>.<listcomp>r�Zworkersrrr�_get_worker_sentinelss�zPool._get_worker_sentinelscCsPd}ttt|���D]6}||}|jdk	rt�d|�|��d}||=q|S)NF�cleaning up worker %dT)�reversed�ranger�rqrrAr()�poolZcleanedrLrRrrr�_join_exited_workerss
zPool._join_exited_workerscCs0|�|j|j|j|j|j|j|j|j|j	|j
�
Sr)�_repopulate_pool_staticr`rYror^rvrwrhrirgrxrrrrrp.s�zPool._repopulate_poolc

Csft|t|��D]P}
||t||||||	fd�}|j�dd�|_d|_|��|�|�t�	d�qdS)Nr[rYZ
PoolWorkerTzadded worker)
r�r�rR�name�replacerzr{�appendrrA)rZrYr�r�rErFrGrHr�rIrL�wrrrr�7s��
zPool._repopulate_pool_staticc

Cs*t�|�r&t�||||||||||	�
dSr)rr�r�)
rZrYr�r�rErFrGrHr�rIrrr�_maintain_poolJs
�zPool._maintain_poolcCs4|j��|_|j��|_|jjj|_|jjj|_	dSr)
r`rcrvrwr5�sendr}r>�recvr�rrrrraVszPool._setup_queuescCs|jtkrtd��dS)NzPool not running)r_rrlrrrr�_check_running\s
zPool._check_runningcCs|�|||���Sr)�apply_asyncr;)rrMrrNrrr�apply`sz
Pool.applycCs|�||t|���Sr)�
_map_asyncrr;�rrM�iterable�	chunksizerrrrgszPool.mapcCs|�||t|���Sr)r�rr;r�rrrrnszPool.starmapcCs|�||t|||�Sr)r�r�rrMr�r��callback�error_callbackrrr�
starmap_asyncvs�zPool.starmap_asyncc
csjz,d}t|�D]\}}||||fifVqWn8tk
rd}z||dt|fifVW5d}~XYnXdS)N���r)�	enumeraterBrC)rZ
result_jobrMr�rL�xrPrrr�_guarded_task_generation~szPool._guarded_task_generationrcCs�|��|dkr:t|�}|j�|�|j||�|jf�|S|dkrPtd�|���t	�
|||�}t|�}|j�|�|jt|�|jf�dd�|D�SdS)NrzChunksize must be 1+, not {0:n}css|]}|D]
}|Vq
qdSrr�r��chunkrWrrr�	<genexpr>�szPool.imap.<locals>.<genexpr>)r��IMapIteratorrdr:r��_job�_set_lengthrlr9r�
_get_tasksr�rrMr�r�rO�task_batchesrrr�imap�s4�������z	Pool.imapcCs�|��|dkr:t|�}|j�|�|j||�|jf�|S|dkrPtd�|���t	�
|||�}t|�}|j�|�|jt|�|jf�dd�|D�SdS)NrzChunksize must be 1+, not {0!r}css|]}|D]
}|Vq
qdSrrr�rrrr��sz&Pool.imap_unordered.<locals>.<genexpr>)r��IMapUnorderedIteratorrdr:r�r�r�rlr9rr�rr�rrr�imap_unordered�s0������zPool.imap_unorderedcCs6|��t|||�}|j�|jd|||fgdf�|S�Nr)r��ApplyResultrdr:r�)rrMrrNr�r�rOrrrr��szPool.apply_asynccCs|�||t|||�Sr)r�rr�rrr�	map_async�s�zPool.map_asyncc
Cs�|��t|d�st|�}|dkrJtt|�t|j�d�\}}|rJ|d7}t|�dkrZd}t�|||�}t||t|�||d�}	|j	�
|�|	j||�df�|	S)N�__len__�rr�r�)
r�r<r�divmodr�r^rr��	MapResultrdr:r�r�)
rrMr�Zmapperr�r�r�Zextrar�rOrrrr��s,
����zPool._map_asynccCs"t||d�|��s|��qdS)N)�timeout)r	�emptyr;)r��change_notifierr�rrr�_wait_for_updates�szPool._wait_for_updatescCspt��}|jtks |rX|jtkrX|�|||||||	|
||�
|�|�|
�}|�||�q|�d�t	�
d�dS)Nzworker handler exiting)rt�current_threadr_rr
r�r�r�r:rrA)r��cache�	taskqueuerZrYr�r�rErFrGrHr�rIr�r��threadZcurrent_sentinelsrrrru�s�
zPool._handle_workersc

Cspt��}t|jd�D]�\}}d}z�|D]�}|jtkrBt�d�q�z||�Wq&tk
r�}
zB|dd�\}	}z||	�	|d|
f�Wnt
k
r�YnXW5d}
~
XYq&Xq&|r�t�d�|r�|dnd}||d�W�qW�
�q
W5d}}}	Xqt�d�z6t�d�|�d�t�d	�|D]}|d��q.Wn tk
�r`t�d
�YnXt�d�dS)Nz'task handler found thread._state != RUN�Fzdoing set_length()rr�ztask handler got sentinelz/task handler sending sentinel to result handlerz(task handler sending sentinel to workersz/task handler got OSError when sending sentinelsztask handler exiting)
rtr��iterr;r_rrrArB�_set�KeyErrorr:r@)
r�r:rFr�r�r�ZtaskseqZ
set_lengthrJrKrP�idxr�rrrr|sB






zPool._handle_tasksc	Cs�t��}z
|�}Wn$ttfk
r6t�d�YdSX|jtkrNt�d�q�|dkrbt�d�q�|\}}}z||�||�Wnt	k
r�YnXd}}}q|�r@|jt
k�r@z
|�}Wn$ttfk
r�t�d�YdSX|dk�r�t�d�q�|\}}}z||�||�Wnt	k
�r0YnXd}}}q�t|d��r�t�d�z,td�D]}|j
���sv�q�|��q`Wnttfk
�r�YnXt�dt|�|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)rtr�r@r?rrAr_rr�r�r
r<r�r>�pollr�)rFr;r�r�rJrKrL�objrrrr:s\











�zPool._handle_resultsccs0t|�}tt�||��}|s dS||fVqdSr)r��tupler�islice)rM�it�sizer�rrrr�vs
zPool._get_taskscCstd��dS)Nz:pool objects cannot be passed between processes or pickled)�NotImplementedErrorrrrrr+s�zPool.__reduce__cCs2t�d�|jtkr.t|_t|j_|j�d�dS)Nzclosing pool)rrAr_rrryrer:rrrrr=�s


z
Pool.closecCst�d�t|_|��dS)Nzterminating pool)rrAr
r_r�rrrrrr�s
zPool.terminatecCsjt�d�|jtkrtd��n|jttfkr4td��|j��|j	��|j
��|jD]}|��qXdS)Nzjoining poolzPool is still runningzIn unknown state)rrAr_rrlrr
ryr(r~r�r^)rr�rrrr(�s






z	Pool.joincCs@t�d�|j��|��r<|j��r<|j��t�	d�qdS)Nz7removing tasks from inqueue until task handler finishedr)
rrAZ_rlock�acquire�is_aliver>r�r��time�sleep)rE�task_handlerr�rrr�_help_stuff_finish�s



zPool._help_stuff_finishc
CsXt�d�t|_|�d�t|_t�d�|�||t|��|��sXt|	�dkrXtd��t|_|�d�|�d�t�d�t	�
�|k	r�|��|r�t|dd�r�t�d�|D]}
|
j
dkr�|
��q�t�d�t	�
�|k	r�|��t�d	�t	�
�|k	�r|��|�rTt|dd��rTt�d
�|D](}
|
���r*t�d|
j�|
���q*dS)Nzfinalizing poolz&helping task handler/workers to finishrz.Cannot have cache with result_hander not alivezjoining worker handlerrrzterminating workerszjoining task handlerzjoining result handlerzjoining pool workersr�)rrAr
r_r:r�r�r�r8rtr�r(r<rqrr�pid)r�r�rErFr�r�Zworker_handlerr�Zresult_handlerr�r�rrrr��sB


�









zPool._terminate_poolcCs|��|Sr)r�rrrr�	__enter__�szPool.__enter__cCs|��dSr)rr)r�exc_typeZexc_valZexc_tbrrr�__exit__�sz
Pool.__exit__)NNrNN)N)N)NNN)r)r)NNN)NNN)N),r r!r"rx�staticmethodrYr�warnings�warnrr�r3rsr�r�rpr�r�rar�r�rrr�r�r�r�r�r�r�r��classmethodrur|rr�r+r=rrr(r�r�r�r�rrrrr�sv
�
P

	



�


�

�
�


-
;


5c@s@eZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�ZdS)r�cCs>||_t��|_tt�|_|j|_||_||_	||j|j<dSr)
r^rtZEvent�_event�next�job_counterr�rf�	_callback�_error_callback)rr�r�r�rrrr�s

zApplyResult.__init__cCs
|j��Sr)r�Zis_setrrrr�ready�szApplyResult.readycCs|��std�|���|jS)Nz{0!r} not ready)r�rlr9�_successrrrr�
successful�szApplyResult.successfulNcCs|j�|�dSr)r�r	�rr�rrrr	�szApplyResult.waitcCs,|�|�|��st�|jr"|jS|j�dSr)r	r�rr��_valuer�rrrr;�s
zApplyResult.getcCsZ|\|_|_|jr$|jr$|�|j�|jr<|js<|�|j�|j��|j|j=d|_dSr)	r�r�r�r�r��setrfr�r^�rrLr�rrrr�s

zApplyResult._set)N)N)	r r!r"rr�r�r	r;r�rrrrr��s	

	r�c@seZdZdd�Zdd�ZdS)r�cCshtj||||d�d|_dg||_||_|dkrNd|_|j��|j|j	=n||t
||�|_dS)Nr�Tr)r�rr�r��
_chunksize�_number_leftr�r�rfr��bool)rr�r��lengthr�r�rrrrs
�
zMapResult.__init__cCs�|jd8_|\}}|rv|jrv||j||j|d|j�<|jdkr�|jrZ|�|j�|j|j=|j��d|_	nL|s�|jr�d|_||_|jdkr�|j
r�|�
|j�|j|j=|j��d|_	dS)NrrF)r�r�r�r�r�rfr�r�r�r^r�)rrLZsuccess_result�successrOrrrr�$s&







zMapResult._setN)r r!r"rr�rrrrr�s
r�c@s:eZdZdd�Zdd�Zddd�ZeZdd	�Zd
d�ZdS)
r�cCsT||_t�t���|_tt�|_|j|_t	�
�|_d|_d|_
i|_||j|j<dSr�)r^rtZ	ConditionZLock�_condr�r�r�rf�collections�deque�_items�_index�_length�	_unsorted)rr�rrrrBs

zIMapIterator.__init__cCs|Srrrrrr�__iter__MszIMapIterator.__iter__NcCs�|j��z|j��}Wnztk
r�|j|jkr>d|_td�|j�|�z|j��}Wn2tk
r�|j|jkr�d|_td�t	d�YnXYnXW5QRX|\}}|r�|S|�dSr)
r�r��popleft�
IndexErrorr�rr^�
StopIterationr	r)rr�rWr�r/rrrr�Ps&zIMapIterator.nextc	Cs�|j��|j|krn|j�|�|jd7_|j|jkrb|j�|j�}|j�|�|jd7_q,|j��n
||j|<|j|jkr�|j|j	=d|_
W5QRXdS�Nr)r�r�r�r�r�pop�notifyrrfr�r^r�rrrr�hs


zIMapIterator._setc	CsB|j�2||_|j|jkr4|j��|j|j=d|_W5QRXdSr)r�rr�rrfr�r^)rr�rrrr�ys

zIMapIterator._set_length)N)	r r!r"rrr��__next__r�r�rrrrr�@s
r�c@seZdZdd�ZdS)r�c	CsV|j�F|j�|�|jd7_|j��|j|jkrH|j|j=d|_W5QRXdSr)	r�r�r�r�rrrfr�r^r�rrrr��s

zIMapUnorderedIterator._setN)r r!r"r�rrrrr��sr�c@sVeZdZdZedd��Zddd�Zdd	�Zd
d�Zedd
��Z	edd��Z
dd�ZdS)rFcOsddlm}|||�S)NrrX)ZdummyrY)rZrrNrYrrrrY�szThreadPool.ProcessNrcCst�||||�dSr)rr)rr�rGrHrrrr�szThreadPool.__init__cCs,t��|_t��|_|jj|_|jj|_dSr)rbrcrvrwr:r}r;r�rrrrra�s


zThreadPool._setup_queuescCs
|jjgSr)rer>rrrrrs�szThreadPool._get_sentinelscCsgSrrr�rrrr��sz ThreadPool._get_worker_sentinelscCsFz|jdd�qWntjk
r(YnXt|�D]}|�d�q2dS)NF)�block)r;rbrr�r:)rEr�r�rLrrrr��szThreadPool._help_stuff_finishcCst�|�dSr)r�r�)rr�r�r�rrrr��szThreadPool._wait_for_updates)NNr)r r!r"rxr�rYrrarsr�r�r�rrrrr�s




)NrNF))�__all__r�rrjrbrtr�r%r�rr$rrrZ
connectionr	r
rrr
�countr�rrrBrr#r*r-rRrC�dictrS�objectrr�ZAsyncResultr�r�r�rrrrr�<module>
sN	�
-=)+E