AlkantarClanX12

Your IP : 18.188.227.108


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-2.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,cs.eZdZ	�fdd�Zdd�Zdd�Z�ZS)�MaybeEncodingErrorcs.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$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�hasattrr8�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




�
������rUcCs	|�r
r)ZexrrrrF�srFcs0eZdZ	dd��fdd�
Z�fdd�Z�ZS)�
_PoolCacheN��notifiercs||_t�j|i|��dSr
)rXr3r)rrXrrQr4rrr�sz_PoolCache.__init__cs$t��|�|s|j�d�dSdSr
)r3�__delitem__rXr=)r�itemr4rrrY�s�z_PoolCache.__delitem__)r"r#r$rrYr7rrr4rrV�srVc@s�eZdZ	dZedd��Z		dKdd�Zeje	fdd	�Z
d
d�Zdd
�Zedd��Z
edd��Zdd�Zedd��Zedd��Zdd�Zdd�Zdifdd�ZdLdd�ZdLd d!�Z		dMd"d#�Zd$d%�ZdNd'd(�ZdNd)d*�Zdiddfd+d,�Z		dMd-d.�Z		dMd/d0�ZedLd1d2��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)OrTcOs|j|i|��Sr
��Process)�ctxrrQrrrr\�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)NrWrz&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_notifierrV�_cache�_maxtasksperchild�_initializer�	_initargs�os�	cpu_count�
ValueErrorr9r:�callable�	TypeError�
_processes�_repopulate_poolrE�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�	processesrJrK�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 )�sourcerh)rb�ResourceWarning�getattrrhr=)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$rb�lenra)r�clsrrrr6s��z
Pool.__repr__cCs |jjg}|jjg}g|�|�Sr
)rzrArh)rZtask_queue_sentinelsZself_notifier_sentinelsrrrrvs

zPool._get_sentinelscCsdd�|D�S)NcSsg|]
}t|d�r|j�qS)�sentinel)r?r�)�.0rUrrr�
<listcomp>s�z.Pool._get_worker_sentinels.<locals>.<listcomp>r�Zworkersrrr�_get_worker_sentinelss�zPool._get_worker_sentinelscCsR	d}ttt|���D]}||}|jdur&t�d|�|��d}||=q|S)NF�cleaning up worker %dT)�reversed�ranger�rtrrDr*)�poolZcleanedrOrUrrr�_join_exited_workers!s
�zPool._join_exited_workerscCs0|�|j|j|j|j|j|j|j|j|j	|j
�
Sr
)�_repopulate_pool_staticrcr\rrraryrzrkrlrjr{r rrrrs1s�zPool._repopulate_poolc

Csh	t|t|��D](}
||t||||||	fd�}|j�dd�|_d|_|��|�|�t�	d�q	dS)Nr^r\Z
PoolWorkerTzadded worker)
r�r�rU�name�replacer}r~�appendrrD)r]r\r�r�rHrIrJrKr�rLrO�wrrrr�:s��
�zPool._repopulate_pool_staticc

Cs0	t�|�rt�||||||||||	�
dSdSr
)rr�r�)
r]r\r�r�rHrIrJrKr�rLrrr�_maintain_poolMs
��zPool._maintain_poolcCs4|j��|_|j��|_|jjj|_|jjj|_	dSr
)
rcrfryrzr8�sendr�rA�recvr�r rrrrdYszPool._setup_queuescCs|jtkr	td��dS)NzPool not running)rbr
ror rrr�_check_running_s
�zPool._check_runningcCs	|�|||���Sr
)�apply_asyncr>)rrPrrQrrr�applycsz
Pool.applycC�	|�||t|���Sr
)�
_map_asyncrr>�rrP�iterable�	chunksizerrrrjszPool.mapcCr�r
)r�rr>r�rrrrqszPool.starmapcC�	|�||t|||�Sr
)r�r�rrPr�r��callback�error_callbackrrr�
starmap_asyncys�zPool.starmap_asyncc
csp�	zd}t|�D]
\}}||||fifVq	WdSty7}z||dt|fifVWYd}~dSd}~ww)N���r)�	enumeraterErF)rZ
result_jobrPr�rO�xrSrrr�_guarded_task_generation�s��$��zPool._guarded_task_generationrcC�	|��|dkrt|�}|j�|�|j||�|jf�|S|dkr)td�|���t	�
|||�}t|�}|j�|�|jt|�|jf�dd�|D�S)NrzChunksize must be 1+, not {0:n}cs��|]
}|D]}|VqqdSr
r�r��chunkrZrrr�	<genexpr>���zPool.imap.<locals>.<genexpr>)r��IMapIteratorrgr=r��_job�_set_lengthror<r�
_get_tasksr�rrPr�r�rR�task_batchesrrr�imap�s6�������z	Pool.imapcCr�)NrzChunksize must be 1+, not {0!r}csr�r
rr�rrrr��r�z&Pool.imap_unordered.<locals>.<genexpr>)r��IMapUnorderedIteratorrgr=r�r�r�ror<rr�rr�rrr�imap_unordered�s2������zPool.imap_unorderedcCs8	|��t|||�}|j�|jd|||fgdf�|S�Nr)r��ApplyResultrgr=r�)rrPrrQr�r�rRrrrr��s
zPool.apply_asynccCr�r
)r�rr�rrr�	map_async�s�zPool.map_asyncc
Cs�	|��t|d�st|�}|dur&tt|�t|j�d�\}}|r&|d7}t|�dkr.d}t�|||�}t||t|�||d�}	|j	�
|�|	j||�df�|	S)N�__len__�rr�r�)
r�r?r�divmodr�rarr��	MapResultrgr=r�r�)
rrPr�Zmapperr�r�r�Zextrar�rRrrrr��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)rw�current_threadrbr
rr�r�r�r=rrD)r��cache�	taskqueuer]r\r�r�rHrIrJrKr�rLr�r��threadZcurrent_sentinelsrrrrx�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)
rwr��iterr>rbr
rrDrE�_set�KeyErrorr=rC)
r�r=rIr�r�r�ZtaskseqZ
set_lengthrMrSrN�idxr�rrrrsN

���
�




��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 sentinelrAz"ensuring that outqueue is not full�
z7result handler exiting: len(cache)=%s, thread._state=%s)rwr�rCrBrrDrbr
r�r�rr?r�rA�pollr�)rIr>r�r�rMrNrO�objrrrr�=sl

�



��

�

��


��
�zPool._handle_resultsccs0�t|�}	tt�||��}|sdS||fVqr
)r��tupler�islice)rP�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)rrDrbr
rr|rhr=r rrrr@�s

�z
Pool.closecCst�d�t|_|��dS)Nzterminating pool)rrDrrbr�r rrrru�s
zPool.terminatecCsht�d�|jtkrtd��|jttfvrtd��|j��|j	��|j
��|jD]}|��q+dS)Nzjoining poolzPool is still runningzIn unknown state)rrDrbr
rorrr|r*r�r�ra)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)
rrDZ_rlock�acquire�is_aliverAr�r��time�sleep)rH�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 handlerruzterminating workerszjoining task handlerzjoining result handlerzjoining pool workersr�)rrDrrbr=r�r�r�r;rwr�r*r?rtru�pid)r�r�rHrIr�r�Zworker_handlerr�Zresult_handlerr�r�rrrr��sJ


�




�


��zPool._terminate_poolcCs|��|Sr
)r�r rrr�	__enter__�szPool.__enter__cCs|��dSr
)ru)r�exc_typeZexc_valZexc_tbrrr�__exit__�rz
Pool.__exit__)NNrNNr
)NNN)r),r"r#r$r{�staticmethodr\r�warnings�warnr
r�r6rvr�r�rsr�r�rdr�r�rrr�r�r�r�r�r�r�r��classmethodrxrr�r�r-r@rur*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
)
rarwZEvent�_event�next�job_counterr�ri�	_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�ror<�_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��setrir�ra�rrOr�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�rir��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�rir�r�r�rar�)rrOZsuccess_result�successrRrrrr�)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�)rarwZ	ConditionZLock�_condr�r�r�ri�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�
IndexErrorr
rra�
StopIterationrr)rr�rZrr2rrrr�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)rr
r	r�r�pop�notifyrrir�rar�rrrr�ms"
�

�"�zIMapIterator._setcCsh|j�'||_|j|jkr"|j��|j|j=d|_Wd�dSWd�dS1s-wYdSr
)rrr
rrir�ra)rrrrrr�~s

�"�zIMapIterator._set_lengthr
)	r"r#r$rr
r��__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�r
rrrir�rar�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]rrQr\rrrr\�szThreadPool.ProcessNrcCst�||||�dSr
)rr)rr�rJrKrrrr�szThreadPool.__init__cCs,t��|_t��|_|jj|_|jj|_dSr
)rerfryrzr=r�r>r�r rrrrd�s


zThreadPool._setup_queuescCs
|jjgSr
)rhrAr rrrrv�rzThreadPool._get_sentinelscCsgSr
rr�rrrr��sz ThreadPool._get_worker_sentinelscCsBz	|jdd�qtjyYnwt|�D]}|�d�qdS)NTF)�block)r>reZEmptyr�r=)rHr�r�rOrrrr��s���zThreadPool._help_stuff_finishcCst�|�dSr
)r�r�)rr�r�r�rrrr��szThreadPool._wait_for_updates)NNr)r"r#r$r{r�r\rrdrvr�r�r�rrrrr�s




)NrNF))�__all__rrrmrerwr�r'r�r�r&rrrZ
connectionrr	r
rr�countr�rrrErr%r,r0rUrF�dictrV�objectrr�ZAsyncResultr�r�r�rrrrr�<module>sP		
�-@++E