AlkantarClanX12

Your IP : 3.138.135.4


Current Path : /proc/self/root/opt/alt/python39/lib64/python3.9/multiprocessing/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python39/lib64/python3.9/multiprocessing/__pycache__/pool.cpython-39.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)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�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!�__doc__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�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|�dS)z@Pickle-able helper function for use by _guarded_task_generation.Nr)ZexrrrrC�srCcs2eZdZdZdd��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
)rUr/r)rrUrrNr0rrr�sz_PoolCache.__init__cs t��|�|s|j�d�dSr
)r/�__delitem__rUr:)r�itemr0rrrV�sz_PoolCache.__delitem__)rr r!r3rrVr4rrr0rrS�srSc@s�eZdZdZdZedd��ZdLdd�Zej	e
fd	d
�Zdd�Zd
d�Z
edd��Zedd��Zdd�Zedd��Zedd��Zdd�Zdd�Zdifdd�ZdMdd �ZdNd!d"�ZdOd#d$�Zd%d&�ZdPd(d)�ZdQd*d+�Zdiddfd,d-�ZdRd.d/�ZdSd0d1�ZedTd2d3��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)UrzS
    Class which supports an async version of applying functions to arguments.
    TcOs|j|i|��Sr
��Process)�ctxrrNrrrrY�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)	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�dur:|j�d�dS)Nz&unclosed running multiprocessing pool )�sourcere)r_�ResourceWarning�getattrrer:)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
)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}||}|jdurt�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�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)z�Bring the number of pool processes up to the specified number,
        for use after reaping workers which have exited.
        r[rYZ
PoolWorkerTzadded workerN)
r�r�rR�name�replacerzr{�appendrrA)rZrYr�r�rErFrGrHr�rIrL�wrrrr�7s��
zPool._repopulate_pool_staticc

Cs*t�|�r&t�||||||||||	�
dS)zEClean up any exited workers and start replacements for them.
        N)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_r
rlrrrr�_check_running\s
zPool._check_runningcCs|�|||���S)zT
        Equivalent of `func(*args, **kwds)`.
        Pool must be running.
        )�apply_asyncr;)rrMrrNrrr�apply`sz
Pool.applycCs|�||t|���S)zx
        Apply `func` to each element in `iterable`, collecting the results
        in a list that is returned.
        )�
_map_asyncrr;�rrM�iterable�	chunksizerrrrgszPool.mapcCs|�||t|���S)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�rrrrnszPool.starmapcCs|�||t|||�S)z=
        Asynchronous version of `starmap()` method.
        )r�r�rrMr�r��callback�error_callbackrrr�
starmap_asyncvs�zPool.starmap_asyncc
cslz,d}t|�D]\}}||||fifVqWn:tyf}z"||dt|fifVWYd}~n
d}~00dS)z�Provides a generator of tasks for imap and imap_unordered with
        appropriate handling for iterables which throw exceptions during
        iteration.���rN)�	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)zP
        Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
        rzChunksize must be 1+, not {0:n}css|]}|D]
}|Vq
qdSr
r�r��chunkrWrrr�	<genexpr>��zPool.imap.<locals>.<genexpr>N)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)zL
        Like `imap()` method but ordering of results is arbitrary.
        rzChunksize must be 1+, not {0!r}css|]}|D]
}|Vq
qdSr
rr�rrrr��r�z&Pool.imap_unordered.<locals>.<genexpr>N)r��IMapUnorderedIteratorrdr:r�r�r�rlr9rr�rr�rrr�imap_unordered�s0������zPool.imap_unorderedcCs6|��t|||�}|j�|jd|||fgdf�|S)z;
        Asynchronous version of `apply()` method.
        rN)r��ApplyResultrdr:r�)rrMrrNr�r�rOrrrr��szPool.apply_asynccCs|�||t|||�S)z9
        Asynchronous version of `map()` method.
        )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)zY
        Helper function to implement map, starmap and their async counterparts.
        �__len__N�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Cstt��}|jtks |r\|jtkr\|�|||||||	|
||�
g|�|��|
�}|�||�q|�d�t	�
d�dS)Nzworker handler exiting)rt�current_threadr_r
rr�r�r�r:rrA)r��cache�	taskqueuerZrYr�r�rErFrGrHr�rIr�r��threadZcurrent_sentinelsrrrru�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)
rtr��iterr;r_r
rrArB�_set�KeyErrorr:r@)
r�r:rFr�r�r�ZtaskseqZ
set_lengthrJrPrK�idxr�rrrr|sJ


��



zPool._handle_tasksc	Cs�t��}z
|�}Wn"ttfy4t�d�YdS0|jtkr^|jtksRJd��t�d�q�|durrt�d�q�|\}}}z||�	||�Wnt
y�Yn0d}}}q|�rJ|jtk�rJz
|�}Wn"ttfy�t�d�YdS0|du�rt�d�q�|\}}}z||�	||�Wnt
�y:Yn0d}}}q�t|d��r�t�d�z,td�D]}|j
���s��q�|��qjWnttf�y�Yn0t�d	t|�|j�dS)
Nz.result handler got EOFError/OSError -- exitingzThread not in TERMINATEz,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_r
r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_r
rryrer:rrrrr=�s


z
Pool.closecCst�d�t|_|��dS)Nzterminating pool)rrArr_r�rrrrrr�s
zPool.terminatecCsjt�d�|jtkrtd��n|jttfvr4td��|j��|j	��|j
��|jD]}|��qXdS)Nzjoining poolzPool is still runningzIn unknown state)rrAr_r
rlrr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	�
�|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 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)-rr r!r3rx�staticmethodrYr�warnings�warnr
r�r2rsr�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@sJeZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�Ze	e
j�ZdS)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
)rr�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)
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�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)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<dS)Nr)r^rtZ	ConditionZLock�_condr�r�r�rf�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�rWr�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�notifyrrfr�r^r�rrrr�js


zIMapIterator._setcCsV|j�<||_|j|jkr4|j��|j|j=d|_Wd�n1sH0YdSr
)r�rrrrfr�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�rrrrfr�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)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_sentinelscCsgSr
rr�rrrr��sz ThreadPool._get_worker_sentinelscCsDz|jdd�qWntjy&Yn0t|�D]}|�d�q0dS)NF)�block)r;rbZEmptyr�r:)rEr�r�rLrrrr��szThreadPool._help_stuff_finishcCst�|�dSr
)r�r�)rr�r�r�rrrr��szThreadPool._wait_for_updates)NNr)rr r!rxr�rYrrarsr�r�r�rrrrr�s




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