Your IP : 18.118.252.215


Current Path : /opt/alt/python310/lib64/python3.10/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/multiprocessing/__pycache__/pool.cpython-310.opt-1.pyc

o

6��f��@sdddgZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZm
Z
ddlmZdZd	Zd
ZdZe��Zdd
�Zdd�ZGdd�de�ZGdd�d�Zdd�ZGdd�de�Z		d*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�;/opt/alt/python310/lib64/python3.10/multiprocessing/pool.py�mapstar/�rcCstt�|d|d��S)Nrr)r�	itertools�starmaprrrr�starmapstar2src@�eZdZdd�Zdd�ZdS)�RemoteTracebackcCs
||_dSr
��tb)�selfrrrr�__init__:�
zRemoteTraceback.__init__cCs|jSr
r�rrrr�__str__<szRemoteTraceback.__str__N)�__name__�
__module__�__qualname__rr!rrrrr9src@r)�ExceptionWithTracebackcCs0t�t|�||�}d�|�}||_d||_dS)N�z

"""
%s""")�	traceback�format_exception�type�join�excr)rr+rrrrr@s
zExceptionWithTraceback.__init__cCst|j|jffSr
)�rebuild_excr+rr rrr�
__reduce__E�z!ExceptionWithTraceback.__reduce__N)r"r#r$rr-rrrrr%?sr%cCst|�|_|Sr
)r�	__cause__)r+rrrrr,Hs
r,cs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�MaybeEncodingErrorzVWraps possible unpickleable errors, so they can be
    safely sent through the socket.cs.t|�|_t|�|_tt|��|j|j�dSr
)�reprr+�value�superr0r)rr+r2��	__class__rrrTs

zMaybeEncodingError.__init__cCsd|j|jfS)Nz(Error sending result: '%s'. Reason: '%s')r2r+r rrrr!Ys�zMaybeEncodingError.__str__cCsd|jj|fS)Nz<%s: %s>)r5r"r rrr�__repr__]r.zMaybeEncodingError.__repr__)r"r#r$�__doc__rr!r6�
__classcell__rrr4rr0Ps
r0rFc
Cs�|durt|t�r
|dkstd�|���|j}|j}t|d�r)|j��|j	��|dur1||�d}|dus=|r�||kr�z|�}	Wnt
tfyRt�
d�Yn�w|	dur]t�
d�n�|	\}
}}}
}zd||
i|��f}Wn"ty�}z|r�|tur�t||j�}d|f}WYd}~nd}~wwz	||
||f�Wn)ty�}zt||d�}t�
d	|�||
|d|ff�WYd}~nd}~wwd}	}
}}}
}|d7}|dus=|r�||ks=t�
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�hasattrr9�close�_reader�EOFError�OSErrorr�debug�	Exception�_helper_reraises_exceptionr%�
__traceback__r0)�inqueue�outqueue�initializer�initargsZmaxtasks�wrap_exceptionr>r?Z	completed�task�job�i�funcr�kwds�result�e�wrappedrrr�workerasX




�
������rVcCs|�)z@Pickle-able helper function for use by _guarded_task_generation.r)ZexrrrrG��rGcs2eZdZdZdd��fdd�
Z�fdd�Z�ZS)�
_PoolCachez�
    Class that implements a cache for the Pool class that will notify
    the pool management threads every time the cache is emptied. The
    notification is done by the use of a queue that is provided when
    instantiating the cache.
    N��notifiercs||_t�j|i|��dSr
)rZr3r)rrZrrRr4rrr�sz_PoolCache.__init__cs$t��|�|s|j�d�dSdSr
)r3�__delitem__rZr>)r�itemr4rrr[�s�z_PoolCache.__delitem__)r"r#r$r7rr[r8rrr4rrX�srXc@s�eZdZdZdZedd��Z		dLdd�Zej	e
fd	d
�Zdd�Zd
d�Z
edd��Zedd��Zdd�Zedd��Zedd��Zdd�Zdd�Zdifdd�ZdMdd �ZdMd!d"�Z		dNd#d$�Zd%d&�ZdOd(d)�ZdOd*d+�Zdiddfd,d-�Z		dNd.d/�Z		dNd0d1�ZedMd2d3��Ze d4d5��Z!ed6d7��Z"ed8d9��Z#ed:d;��Z$d<d=�Z%d>d?�Z&d@dA�Z'dBdC�Z(edDdE��Z)e dFdG��Z*dHdI�Z+dJdK�Z,dS)PrzS
    Class which supports an async version of applying functions to arguments.
    TcOs|j|i|��Sr
��Process)�ctxrrRrrrr^�szPool.ProcessNrcCs0g|_t|_|p
t�|_|��t��|_|j��|_	t
|j	d�|_||_||_
||_|dur5t��p4d}|dkr=td��|durNt|t�rJ|dkrNtd��|durZt|�sZtd��||_z|��Wn!ty�|jD]}|jdurx|��qm|jD]}|��q|�w|��}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/j0||j1|j|j"|j#|j|j	|j%|j+|j.|jf	d	d
�|_2t'|_dS)NrYrz&Number of processes must be at least 1rz/maxtasksperchild must be a positive int or Nonezinitializer must be a callable��targetrT�)rZexitpriority)3�_poolr	�_stater�_ctx�
_setup_queues�queue�SimpleQueue�
_taskqueue�_change_notifierrX�_cache�_maxtasksperchild�_initializer�	_initargs�os�	cpu_count�
ValueErrorr:r;�callable�	TypeError�
_processes�_repopulate_poolrF�exitcode�	terminater*�_get_sentinels�	threadingZThreadr�_handle_workersr^�_inqueue�	_outqueue�_wrap_exception�_worker_handler�daemonr
�start�
_handle_tasks�
_quick_put�
_task_handler�_handle_results�
_quick_get�_result_handlerrZFinalize�_terminate_pool�
_terminate)r�	processesrKrL�maxtasksperchild�context�p�	sentinelsrrrr�s�


�

�
��
��
�
��
z
Pool.__init__cCsF|j|kr|d|��t|d�t|dd�dur!|j�d�dSdSdS)Nz&unclosed running multiprocessing pool )�sourcerj)rd�ResourceWarning�getattrrjr>)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=�>)r5r#r$rd�lenrc)r�clsrrrr6s��z
Pool.__repr__cCs |jjg}|jjg}g|�|�Sr
)r|rBrj)rZtask_queue_sentinelsZself_notifier_sentinelsrrrrxs

zPool._get_sentinelscCsdd�|D�S)NcSsg|]
}t|d�r|j�qS)�sentinel)r@r�)�.0rVrrr�
<listcomp>s�z.Pool._get_worker_sentinels.<locals>.<listcomp>r�Zworkersrrr�_get_worker_sentinelss�zPool._get_worker_sentinelscCsPd}ttt|���D]}||}|jdur%t�d|�|��d}||=q
|S)z�Cleanup after any worker processes which have exited due to reaching
        their specified lifetime.  Returns True if any workers were cleaned up.
        FN�cleaning up worker %dT)�reversed�ranger�rvrrEr*)�poolZcleanedrPrVrrr�_join_exited_workers!s
�zPool._join_exited_workerscCs0|�|j|j|j|j|j|j|j|j|j	|j
�
Sr
)�_repopulate_pool_staticrer^rtrcr{r|rmrnrlr}r rrrru1s�zPool._repopulate_poolc

Csft|t|��D](}
||t||||||	fd�}|j�dd�|_d|_|��|�|�t�	d�qdS)z�Bring the number of pool processes up to the specified number,
        for use after reaping workers which have exited.
        r`r^Z
PoolWorkerTzadded workerN)
r�r�rV�name�replacerr��appendrrE)r_r^r�r�rIrJrKrLr�rMrP�wrrrr�:s��
�zPool._repopulate_pool_staticc

Cs.t�|�rt�||||||||||	�
dSdS)zEClean up any exited workers and start replacements for them.
        N)rr�r�)
r_r^r�r�rIrJrKrLr�rMrrr�_maintain_poolMs
��zPool._maintain_poolcCs4|j��|_|j��|_|jjj|_|jjj|_	dSr
)
rerhr{r|r9�sendr�rB�recvr�r rrrrfYszPool._setup_queuescCs|jtkr	td��dS)NzPool not running)rdr
rqr rrr�_check_running_s
�zPool._check_runningcCs|�|||���S)zT
        Equivalent of `func(*args, **kwds)`.
        Pool must be running.
        )�apply_asyncr?)rrQrrRrrr�applycsz
Pool.applycC�|�||t|���S)zx
        Apply `func` to each element in `iterable`, collecting the results
        in a list that is returned.
        )�
_map_asyncrr?�rrQ�iterable�	chunksizerrrrjszPool.mapcCr�)z�
        Like `map()` method but the elements of the `iterable` are expected to
        be iterables as well and will be unpacked as arguments. Hence
        `func` and (a, b) becomes func(a, b).
        )r�rr?r�rrrrqszPool.starmapcC�|�||t|||�S)z=
        Asynchronous version of `starmap()` method.
        )r�r�rrQr�r��callback�error_callbackrrr�
starmap_asyncys�zPool.starmap_asyncc
csn�zd}t|�D]
\}}||||fifVqWdSty6}z||dt|fifVWYd}~dSd}~ww)z�Provides a generator of tasks for imap and imap_unordered with
        appropriate handling for iterables which throw exceptions during
        iteration.���rN)�	enumeraterFrG)rZ
result_jobrQr�rP�xrTrrr�_guarded_task_generation�s��$��zPool._guarded_task_generationrcC�|��|dkrt|�}|j�|�|j||�|jf�|S|dkr(td�|���t	�
|||�}t|�}|j�|�|jt|�|jf�dd�|D�S)zP
        Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
        rzChunksize must be 1+, not {0:n}cs��|]
}|D]}|VqqdSr
r�r��chunkr\rrr�	<genexpr>���zPool.imap.<locals>.<genexpr>)r��IMapIteratorrir>r��_job�_set_lengthrqr=r�
_get_tasksr�rrQr�r�rS�task_batchesrrr�imap�s4�������z	Pool.imapcCr�)zL
        Like `imap()` method but ordering of results is arbitrary.
        rzChunksize must be 1+, not {0!r}csr�r
rr�rrrr��r�z&Pool.imap_unordered.<locals>.<genexpr>)r��IMapUnorderedIteratorrir>r�r�r�rqr=rr�rr�rrr�imap_unordered�s0������zPool.imap_unorderedcCs6|��t|||�}|j�|jd|||fgdf�|S)z;
        Asynchronous version of `apply()` method.
        rN)r��ApplyResultrir>r�)rrQrrRr�r�rSrrrr��szPool.apply_asynccCr�)z9
        Asynchronous version of `map()` method.
        )r�rr�rrr�	map_async�s�zPool.map_asyncc
Cs�|��t|d�s
t|�}|dur%tt|�t|j�d�\}}|r%|d7}t|�dkr-d}t�|||�}t||t|�||d�}	|j	�
|�|	j||�df�|	S)zY
        Helper function to implement map, starmap and their async counterparts.
        �__len__N�rr�r�)
r�r@r�divmodr�rcrr��	MapResultrir>r�r�)
rrQr�Zmapperr�r�r�Zextrar�rSrrrr��s,
����zPool._map_asynccCs,t||d�|��s|��|��r
dSdS)N)�timeout)r�emptyr?)r��change_notifierr�rrr�_wait_for_updates�s�zPool._wait_for_updatescCs�t��}|jtks|r9|jtkr9|�|||||||	|
||�
g|�|��|
�}|�||�|jtks|r9|jtks|�d�t	�
d�dS)Nzworker handler exiting)ry�current_threadrdr
rr�r�r�r>rrE)r��cache�	taskqueuer_r^r�r�rIrJrKrLr�rMr�r��threadZcurrent_sentinelsrrrrz�s��
	zPool._handle_workersc

Cstt��}t|jd�D]z\}}d}zm|D]D}|jtkr!t�d�nTz||�WqtyW}	z$|dd�\}
}z||
�	|d|	f�Wn	t
yLYnwWYd}	~	qd}	~	ww|rmt�d�|re|dnd}||d�Wd}}}
q
Wd}}}
nd}}}
wt�d�zt�d�|�d�t�d	�|D]}|d�q�Wnty�t�d
�Ynwt�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)
ryr��iterr?rdr
rrErF�_set�KeyErrorr>rD)
r�r>rJr�r�r�ZtaskseqZ
set_lengthrNrTrO�idxr�rrrr�sN

���
�




��zPool._handle_tasksc	Cs�t��}	z|�}Wnttfyt�d�YdSw|jtkr't�d�n*|dur1t�d�n |\}}}z
||�||�Wn	t	yIYnwd}}}q|r�|jt
kr�z|�}Wnttfynt�d�YdSw|duryt�d�qQ|\}}}z
||�||�Wn	t	y�Ynwd}}}|r�|jt
ksXt|d�r�t�d�ztd�D]}|j
��s�n|�q�Wnttfy�Ynwt�d	t|�|j�dS)
Nrz.result handler got EOFError/OSError -- exitingz,result handler found thread._state=TERMINATEzresult handler got sentinelz&result handler ignoring extra sentinelrBz"ensuring that outqueue is not full�
z7result handler exiting: len(cache)=%s, thread._state=%s)ryr�rDrCrrErdr
r�r�rr@r�rB�pollr�)rJr?r�r�rNrOrP�objrrrr�=sl

�



��

�

��


��
�zPool._handle_resultsccs0�t|�}	tt�||��}|sdS||fVqr
)r��tupler�islice)rQ�it�sizer�rrrr�ys�
�zPool._get_taskscCstd��)Nz:pool objects cannot be passed between processes or pickled)�NotImplementedErrorr rrrr-�s�zPool.__reduce__cCs6t�d�|jtkrt|_t|j_|j�d�dSdS)Nzclosing pool)rrErdr
rr~rjr>r rrrrA�s

�z
Pool.closecCst�d�t|_|��dS)Nzterminating pool)rrErrdr�r rrrrw�s
zPool.terminatecCsht�d�|jtkrtd��|jttfvrtd��|j��|j	��|j
��|jD]}|��q+dS)Nzjoining poolzPool is still runningzIn unknown state)rrErdr
rqrrr~r*r�r�rc)rr�rrrr*�s






�z	Pool.joincCs\t�d�|j��|��r(|j��r,|j��t�	d�|��r*|j��sdSdSdSdS)Nz7removing tasks from inqueue until task handler finishedr)
rrEZ_rlock�acquire�is_aliverBr�r��time�sleep)rI�task_handlerr�rrr�_help_stuff_finish�s



"�zPool._help_stuff_finishc
CsVt�d�t|_|�d�t|_t�d�|�||t|��|��s,t|	�dkr,td��t|_|�d�|�d�t�d�t	�
�|urH|��|rdt|dd�rdt�d�|D]}
|
j
durc|
��qXt�d�t	�
�|urs|��t�d	�t	�
�|ur�|��|r�t|dd�r�t�d
�|D]}
|
��r�t�d|
j�|
��q�dSdSdS)Nzfinalizing poolz&helping task handler/workers to finishrz.Cannot have cache with result_hander not alivezjoining worker handlerrwzterminating workerszjoining task handlerzjoining result handlerzjoining pool workersr�)rrErrdr>r�r�r�r<ryr�r*r@rvrw�pid)r�r�rIrJr�r�Zworker_handlerr�Zresult_handlerr�r�rrrr��sJ


�




�


��zPool._terminate_poolcCs|��|Sr
)r�r rrr�	__enter__�szPool.__enter__cCs|��dSr
)rw)r�exc_typeZexc_valZexc_tbrrr�__exit__�rz
Pool.__exit__)NNrNNr
)NNN)r)-r"r#r$r7r}�staticmethodr^r�warnings�warnr
r�r6rxr�r�rur�r�rfr�r�rrr�r�r�r�r�r�r�r��classmethodrzr�r�r�r-rArwr*r�r�r�r�rrrrr�sx

�S

	




�


�

�
�

-
;


5c@sJeZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�Ze	e
j�ZdS)r�cCs>||_t��|_tt�|_|j|_||_||_	||j|j<dSr
)
rcryZEvent�_event�next�job_counterr�rk�	_callback�_error_callback)rr�r�r�rrrr�s

zApplyResult.__init__cCs
|j��Sr
)r�Zis_setr rrr�ready�rzApplyResult.readycCs|��std�|���|jS)Nz{0!r} not ready)r�rqr=�_successr rrr�
successful�szApplyResult.successfulNcCs|j�|�dSr
)r�r�rr�rrrr�r.zApplyResult.waitcCs(|�|�|��st�|jr|jS|j�r
)rr�rr��_valuer�rrrr?�s
zApplyResult.getcCsZ|\|_|_|jr|jr|�|j�|jr|js|�|j�|j��|j|j=d|_dSr
)	r�r�r�r�r��setrkr�rc�rrPr�rrrr�s


zApplyResult._setr
)
r"r#r$rr�r�rr?r�r��types�GenericAlias�__class_getitem__rrrrr��s	

	
r�c@r)r�cCsjtj||||d�d|_dg||_||_|dkr(d|_|j��|j|j	=dS||t
||�|_dS)Nr�Tr)r�rr�r��
_chunksize�_number_leftr�r�rkr��bool)rr�r��lengthr�r�rrrrs
�
zMapResult.__init__cCs�|jd8_|\}}|r>|jr>||j||j|d|j�<|jdkr<|jr-|�|j�|j|j=|j��d|_	dSdS|sI|jrId|_||_|jdkrf|j
rW|�
|j�|j|j=|j��d|_	dSdS)NrrF)rr�r�rr�rkr�r�r�rcr�)rrPZsuccess_result�successrSrrrr�)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<dS)Nr)rcryZ	ConditionZLock�_condr�r�r�rk�collections�deque�_items�_index�_length�	_unsorted)rr�rrrrGs

zIMapIterator.__init__cCs|Sr
rr rrr�__iter__RszIMapIterator.__iter__NcCs�|j�Iz|j��}Wn9tyD|j|jkrd|_td�|j�|�z|j��}WntyA|j|jkr>d|_td�t	d�wYnwWd�n1sOwY|\}}|r\|S|�r
)
rr
�popleft�
IndexErrorrrrc�
StopIterationrr)rr�r\rr2rrrr�Us0�����zIMapIterator.nextcCs�|j�\|j|kr<|j�|�|jd7_|j|jvr6|j�|j�}|j�|�|jd7_|j|jvs|j��n||j|<|j|jkrW|j|j	=d|_
Wd�dSWd�dS1sbwYdS�Nr)rrr
r�r
�pop�notifyrrkr�rcr�rrrr�ms"
�

�"�zIMapIterator._setcCsh|j�'||_|j|jkr"|j��|j|j=d|_Wd�dSWd�dS1s-wYdSr
)rrrrrkr�rc)rrrrrr�~s

�"�zIMapIterator._set_lengthr
)	r"r#r$rrr��__next__r�r�rrrrr�Es
r�c@seZdZdd�ZdS)r�cCs||j�1|j�|�|jd7_|j��|j|jkr,|j|j=d|_Wd�dSWd�dS1s7wYdSr)	rr
r�rrrrkr�rcr�rrrr��s

�"�zIMapUnorderedIterator._setN)r"r#r$r�rrrrr��sr�c@sVeZdZdZedd��Zddd�Zdd	�Zd
d�Zedd
��Z	edd��Z
dd�ZdS)rFcOsddlm}||i|��S)Nrr])Zdummyr^)r_rrRr^rrrr^�szThreadPool.ProcessNrcCst�||||�dSr
)rr)rr�rKrLrrrr�szThreadPool.__init__cCs,t��|_t��|_|jj|_|jj|_dSr
)rgrhr{r|r>r�r?r�r rrrrf�s


zThreadPool._setup_queuescCs
|jjgSr
)rjrBr rrrrx�rzThreadPool._get_sentinelscCsgSr
rr�rrrr��rWz ThreadPool._get_worker_sentinelscCsBz	|jdd�qtjyYnwt|�D]}|�d�qdS)NTF)�block)r?rgZEmptyr�r>)rIr�r�rPrrrr��s���zThreadPool._help_stuff_finishcCst�|�dSr
)r�r�)rr�r�r�rrrr��szThreadPool._wait_for_updates)NNr)r"r#r$r}r�r^rrfrxr�r�r�rrrrr�s




)NrNF))�__all__rrrorgryr�r'r�r�r&rrrZ
connectionrr	r
rr�countr�rrrFrr%r,r0rVrG�dictrX�objectrr�ZAsyncResultr�r�r�rrrrr�<module>sP		
�-@++E

?>