AlkantarClanX12

Your IP : 18.188.63.71


Current Path : /opt/alt/python39/lib64/python3.9/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/multiprocessing/__pycache__/pool.cpython-39.opt-2.pyc

a

R�f+�@s`ddgZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZm
Z
ddlmZdZd	Zd
ZdZe��Zdd
�Zdd�ZGdd�de�ZGdd�d�Zdd�ZGdd�de�Zd*dd�Zdd�ZGdd�de�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�)�util)�get_context�TimeoutError)�wait�INIT�RUN�CLOSE�	TERMINATEcCstt|��S�N)�list�map��args�r�9/opt/alt/python39/lib64/python3.9/multiprocessing/pool.py�mapstar/srcCstt�|d|d��S)Nrr)r�	itertools�starmaprrrr�starmapstar2src@seZdZdd�Zdd�ZdS)�RemoteTracebackcCs
||_dSr
��tb)�selfrrrr�__init__:szRemoteTraceback.__init__cCs|jSr
r�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)rr 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>)r1rrrrr�__repr__]szMaybeEncodingError.__repr__)rr r!rrr2�
__classcell__rrr0rr,Psr,rFc
Cs�|dur(t|t�r|dks(td�|���|j}|j}t|d�rR|j��|j	��|durb||�d}|dus~|�r�||k�r�z
|�}	Wn&t
tfy�t�
d�Y�q�Yn0|	dur�t�
d��q�|	\}
}}}
}zd||
i|��f}WnJt�y4}z0|�r|tu�rt||j�}d|f}WYd}~n
d}~00z||
||f�WnTt�y�}z:t||d�}t�
d	|�||
|d|ff�WYd}~n
d}~00d}	}
}}}
}|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�hasattrr4�close�_reader�EOFError�OSErrorr�debug�	Exception�_helper_reraises_exceptionr"�
__traceback__r,)�inqueue�outqueue�initializer�initargsZmaxtasks�wrap_exceptionr9r:Z	completed�task�job�i�funcr�kwds�result�e�wrappedrrr�workerasN�





�(
rQcCs|�dSr
r)ZexrrrrB�srBcs.eZdZdd��fdd�
Z�fdd�Z�ZS)�
_PoolCacheN��notifiercs||_t�j|i|��dSr
)rTr/r)rrTrrMr0rrr�sz_PoolCache.__init__cs t��|�|s|j�d�dSr
)r/�__delitem__rTr9)r�itemr0rrrU�sz_PoolCache.__delitem__)rr r!rrUr3rrr0rrR�srRc@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|i|��Sr
��Process)�ctxrrMrrrrX�szPool.ProcessNrcCsg|_t|_|pt�|_|��t��|_|j��|_	t
|j	d�|_||_||_
||_|durjt��phd}|dkrztd��|dur�t|�s�td��||_z|��WnFty�|jD]}|jdur�|��q�|jD]}|��qւYn0|��}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)	NrSrz&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_notifierrR�_cache�_maxtasksperchild�_initializer�	_initargs�os�	cpu_count�
ValueError�callable�	TypeError�
_processes�_repopulate_poolrA�exitcode�	terminater'�_get_sentinels�	threadingZThreadr�_handle_workersrX�_inqueue�	_outqueue�_wrap_exception�_worker_handler�daemonr
�start�
_handle_tasks�
_quick_put�
_task_handler�_handle_results�
_quick_get�_result_handlerrZFinalize�_terminate_pool�
_terminate)r�	processesrFrG�maxtasksperchild�context�p�	sentinelsrrrr�s~






��
��
�
��z
Pool.__init__cCs>|j|kr:|d|��t|d�t|dd�dur:|j�d�dS)Nz&unclosed running multiprocessing pool )�sourcerd)r^�ResourceWarning�getattrrdr9)rZ_warnr
rrr�__del__s

�zPool.__del__c	Cs0|j}d|j�d|j�d|j�dt|j��d�	S)N�<�.z state=z pool_size=�>)r1r r!r^�lenr])r�clsrrrr2s��z
Pool.__repr__cCs |jjg}|jjg}g|�|�Sr
)rvr=rd)rZtask_queue_sentinelsZself_notifier_sentinelsrrrrrs

zPool._get_sentinelscCsdd�|D�S)NcSsg|]}t|d�r|j�qS)�sentinel)r;r�)�.0rQrrr�
<listcomp>s
�z.Pool._get_worker_sentinels.<locals>.<listcomp>r�Zworkersrrr�_get_worker_sentinelss�zPool._get_worker_sentinelscCsPd}ttt|���D]6}||}|jdurt�d|�|��d}||=q|S)NF�cleaning up worker %dT)�reversed�ranger�rprr@r')�poolZcleanedrKrQrrr�_join_exited_workerss
zPool._join_exited_workerscCs0|�|j|j|j|j|j|j|j|j|j	|j
�
Sr
)�_repopulate_pool_staticr_rXrnr]rurvrgrhrfrwrrrrro.s�zPool._repopulate_poolc

Csft|t|��D]P}
||t||||||	fd�}|j�dd�|_d|_|��|�|�t�	d�qdS)NrZrXZ
PoolWorkerTzadded worker)
r�r�rQ�name�replaceryrz�appendrr@)rYrXr�r�rDrErFrGr�rHrK�wrrrr�7s��
zPool._repopulate_pool_staticc

Cs*t�|�r&t�||||||||||	�
dSr
)rr�r�)
rYrXr�r�rDrErFrGr�rHrrr�_maintain_poolJs
�zPool._maintain_poolcCs4|j��|_|j��|_|jjj|_|jjj|_	dSr
)
r_rbrurvr4�sendr|r=�recvrrrrrr`VszPool._setup_queuescCs|jtkrtd��dS)NzPool not running)r^r
rkrrrr�_check_running\s
zPool._check_runningcCs|�|||���Sr
)�apply_asyncr:)rrLrrMrrr�apply`sz
Pool.applycCs|�||t|���Sr
)�
_map_asyncrr:�rrL�iterable�	chunksizerrrrgszPool.mapcCs|�||t|���Sr
)r�rr:r�rrrrnszPool.starmapcCs|�||t|||�Sr
)r�r�rrLr�r��callback�error_callbackrrr�
starmap_asyncvs�zPool.starmap_asyncc
cslz,d}t|�D]\}}||||fifVqWn:tyf}z"||dt|fifVWYd}~n
d}~00dS)N���r)�	enumeraterArB)rZ
result_jobrLr�rK�xrOrrr�_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
qdSr
r�r��chunkrVrrr�	<genexpr>��zPool.imap.<locals>.<genexpr>)r��IMapIteratorrcr9r��_job�_set_lengthrkr8r�
_get_tasksr�rrLr�r�rN�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
qdSr
rr�rrrr��r�z&Pool.imap_unordered.<locals>.<genexpr>)r��IMapUnorderedIteratorrcr9r�r�r�rkr8rr�rr�rrr�imap_unordered�s0������zPool.imap_unorderedcCs6|��t|||�}|j�|jd|||fgdf�|S�Nr)r��ApplyResultrcr9r�)rrLrrMr�r�rNrrrr��szPool.apply_asynccCs|�||t|||�Sr
)r�rr�rrr�	map_async�s�zPool.map_asyncc
Cs�|��t|d�st|�}|durJtt|�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��	MapResultrcr9r�r�)
rrLr�Zmapperr�r�r�Zextrar�rNrrrr��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Cstt��}|jtks |r\|jtkr\|�|||||||	|
||�
g|�|��|
�}|�||�q|�d�t	�
d�dS)Nzworker handler exiting)rs�current_threadr^r
rr�r�r�r9rr@)r��cache�	taskqueuerYrXr�r�rDrErFrGr�rHr�r��threadZcurrent_sentinelsrrrrt�s�
zPool._handle_workersc

Cs�t��}t|jd�D�]
\}}d}z�|D]�}|jtkrDt�d�q�z||�Wq(ty�}	zH|dd�\}
}z||
�	|d|	f�Wnt
y�Yn0WYd}	~	q(d}	~	00q(|r�t�d�|r�|dnd}||d�Wd}}}
qWd}}}
�q,Wd}}}
qd}}}
0qt�d�z6t�d�|�d�t�d	�|D]}|d��qPWnt�y�t�d
�Yn0t�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)
rsr��iterr:r^r
rr@rA�_set�KeyErrorr9r?)
r�r9rEr�r�r�ZtaskseqZ
set_lengthrIrOrJ�idxr�rrrr{sJ


��



zPool._handle_tasksc	Cs�t��}z
|�}Wn"ttfy4t�d�YdS0|jtkrLt�d�q�|dur`t�d�q�|\}}}z||�||�Wnt	y�Yn0d}}}q|�r6|jt
k�r6z
|�}Wn"ttfy�t�d�YdS0|dur�t�d�q�|\}}}z||�||�Wnt	�y&Yn0d}}}q�t|d��r�t�d�z,td�D]}|j
���sl�qv|��qVWnttf�y�Yn0t�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)rsr�r?r>rr@r^r
r�r�rr;r�r=�pollr�)rEr:r�r�rIrJrK�objrrrr~:sZ











�zPool._handle_resultsccs0t|�}tt�||��}|s dS||fVqdSr
)r��tupler�islice)rL�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)rr@r^r
rrxrdr9rrrrr<�s


z
Pool.closecCst�d�t|_|��dS)Nzterminating pool)rr@rr^r�rrrrrq�s
zPool.terminatecCsjt�d�|jtkrtd��n|jttfvr4td��|j��|j	��|j
��|jD]}|��qXdS)Nzjoining poolzPool is still runningzIn unknown state)rr@r^r
rkrrrxr'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)
rr@Z_rlock�acquire�is_aliver=r�r��time�sleep)rD�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	�
�|ur�|��|r�t|dd�r�t�d�|D]}
|
j
dur�|
��q�t�d�t	�
�|ur�|��t�d	�t	�
�|u�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 handlerrqzterminating workerszjoining task handlerzjoining result handlerzjoining pool workersr�)rr@rr^r9r�r�r�r7rsr�r'r;rprq�pid)r�r�rDrEr�r�Zworker_handlerr�Zresult_handlerr�r�rrrr��sB


�









zPool._terminate_poolcCs|��|Sr
)r�rrrr�	__enter__�szPool.__enter__cCs|��dSr
)rq)r�exc_typeZexc_valZexc_tbrrr�__exit__�sz
Pool.__exit__)NNrNN)N)N)NNN)r)r)NNN)NNN)N),rr r!rw�staticmethodrXr�warnings�warnr
r�r2rrr�r�ror�r�r`r�r�rrr�r�r�r�r�r�r�r��classmethodrtr{r~r�r*r<rqr'r�r�r�r�rrrrr�st
�
P

	



�


�

�
�


-
;


5c@sJeZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�Ze	e
j�ZdS)r�cCs>||_t��|_tt�|_|j|_||_||_	||j|j<dSr
)
r]rsZEvent�_event�next�job_counterr�re�	_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�rkr8�_successrrrr�
successful�szApplyResult.successfulNcCs|j�|�dSr
)r�r�rr�rrrr�szApplyResult.waitcCs,|�|�|��st�|jr"|jS|j�dSr
)rr�rr��_valuer�rrrr:�s
zApplyResult.getcCsZ|\|_|_|jr$|jr$|�|j�|jr<|js<|�|j�|j��|j|j=d|_dSr
)	r�r�r�r�r��setrer�r]�rrKr�rrrr�s

zApplyResult._set)N)N)
rr r!rr�r�rr:r�r��types�GenericAlias�__class_getitem__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�rer��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�rer�r�r�r]r�)rrKZsuccess_result�successrNrrrr�&s&







zMapResult._setN)rr 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]rsZ	ConditionZLock�_condr�r�r�re�collections�deque�_items�_index�_length�	_unsorted)rr�rrrrDs

zIMapIterator.__init__cCs|Sr
rrrrr�__iter__OszIMapIterator.__iter__NcCs�|j��z|j��}Wnvty�|j|jkr<d|_td�|j�|�z|j��}Wn0ty�|j|jkr|d|_td�t	d�Yn0Yn0Wd�n1s�0Y|\}}|r�|S|�dSr
)
r�r�popleft�
IndexErrorrrr]�
StopIterationrr)rr�rVr�r.rrrr�Rs&0zIMapIterator.nextcCs�|j��|j|krn|j�|�|jd7_|j|jvrb|j�|j�}|j�|�|jd7_q,|j��n
||j|<|j|jkr�|j|j	=d|_
Wd�n1s�0YdS�Nr)r�rrr�r�pop�notifyrrer�r]r�rrrr�js


zIMapIterator._setcCsV|j�<||_|j|jkr4|j��|j|j=d|_Wd�n1sH0YdSr
)r�rrrrer�r])rr�rrrr�{s

zIMapIterator._set_length)N)	rr r!rrr��__next__r�r�rrrrr�Bs
r�c@seZdZdd�ZdS)r�cCsj|j�P|j�|�|jd7_|j��|j|jkrH|j|j=d|_Wd�n1s\0YdSr	)	r�rr�rrrrer�r]r�rrrr��s

zIMapUnorderedIterator._setN)rr r!r�rrrrr��sr�c@sVeZdZdZedd��Zddd�Zdd	�Zd
d�Zedd
��Z	edd��Z
dd�ZdS)rFcOsddlm}||i|��S)NrrW)ZdummyrX)rYrrMrXrrrrX�szThreadPool.ProcessNrcCst�||||�dSr
)rr)rr�rFrGrrrr�szThreadPool.__init__cCs,t��|_t��|_|jj|_|jj|_dSr
)rarbrurvr9r|r:rrrrrr`�s


zThreadPool._setup_queuescCs
|jjgSr
)rdr=rrrrrr�szThreadPool._get_sentinelscCsgSr
rr�rrrr��sz ThreadPool._get_worker_sentinelscCsDz|jdd�qWntjy&Yn0t|�D]}|�d�q0dS)NF)�block)r:raZEmptyr�r9)rDr�r�rKrrrr��szThreadPool._help_stuff_finishcCst�|�dSr
)r�r�)rr�r�r�rrrr��szThreadPool._wait_for_updates)NNr)rr r!rwr�rXrr`rrr�r�r�rrrrr�s




)NrNF))�__all__r�rrirarsr�r$r�r�r#rrrZ
connectionrr	r
rr�countr�rrrArr"r)r,rQrB�dictrR�objectrr�ZAsyncResultr�r�r�rrrrr�<module>
sN	�
-=++E