CasperSecurity

Current Path : /lib/python3.10/multiprocessing/__pycache__/
Upload File :
Current File : //lib/python3.10/multiprocessing/__pycache__/pool.cpython-310.pyc

o

`�wi��@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�+/usr/lib/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�initargs�maxtasks�wrap_exceptionr>r?�	completed�task�job�i�funcr�kwds�result�e�wrappedrrr�workerasX




�
������rXcCs|�)z@Pickle-able helper function for use by _guarded_task_generation.r)�exrrrrG��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
)r]r3r)rr]rrTr4rrr�sz_PoolCache.__init__cs$t��|�|s|j�d�dSdSr
)r3�__delitem__r]r>)r�itemr4rrr^�s�z_PoolCache.__delitem__)r"r#r$r7rr^r8rrr4rr[�sr[c@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)�ctxrrTrrrra�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)Nr\rz&Number of processes must be at least 1rz/maxtasksperchild must be a positive int or Nonezinitializer must be a callable��targetrT�)r�exitpriority)3�_poolr	�_stater�_ctx�
_setup_queues�queue�SimpleQueue�
_taskqueue�_change_notifierr[�_cache�_maxtasksperchild�_initializer�	_initargs�os�	cpu_count�
ValueErrorr:r;�callable�	TypeError�
_processes�_repopulate_poolrF�exitcode�	terminater*�_get_sentinels�	threading�Threadr�_handle_workersra�_inqueue�	_outqueue�_wrap_exception�_worker_handler�daemonr
�start�
_handle_tasks�
_quick_put�
_task_handler�_handle_results�
_quick_get�_result_handlerr�Finalize�_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 )�sourcern)rh�ResourceWarning�getattrrnr>)r�_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$rh�lenrg)r�clsrrrr6s��z
Pool.__repr__cCs |jjg}|jjg}g|�|�Sr
)r�rBrn)r�task_queue_sentinels�self_notifier_sentinelsrrrr|s

zPool._get_sentinelscCsdd�|D�S)NcSsg|]
}t|d�r|j�qS)�sentinel)r@r�)�.0rXrrr�
<listcomp>s�z.Pool._get_worker_sentinels.<locals>.<listcomp>r��workersrrr�_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�rzrrEr*)�pool�cleanedrRrXrrr�_join_exited_workers!s
�zPool._join_exited_workerscCs0|�|j|j|j|j|j|j|j|j|j	|j
�
Sr
)�_repopulate_pool_staticrirarxrgr�r�rqrrrpr�r rrrry1s�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.
        rcra�
PoolWorkerTzadded workerN)
r�r�rX�name�replacer�r��appendrrE)rbrar�r�rIrJrKrLr�rNrR�wrrrr�:s��
�zPool._repopulate_pool_staticc

Cs.t�|�rt�||||||||||	�
dSdS)zEClean up any exited workers and start replacements for them.
        N)rr�r�)
rbrar�r�rIrJrKrLr�rNrrr�_maintain_poolMs
��zPool._maintain_poolcCs4|j��|_|j��|_|jjj|_|jjj|_	dSr
)
rirlr�r�r9�sendr�rB�recvr�r rrrrjYszPool._setup_queuescCs|jtkr	td��dS)NzPool not running)rhr
rur rrr�_check_running_s
�zPool._check_runningcCs|�|||���S)zT
        Equivalent of `func(*args, **kwds)`.
        Pool must be running.
        )�apply_asyncr?)rrSrrTrrr�applycsz
Pool.applycC�|�||t|���S)zx
        Apply `func` to each element in `iterable`, collecting the results
        in a list that is returned.
        )�
_map_asyncrr?�rrS�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�rrSr�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)r�
result_jobrSr�rR�xrVrrr�_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��IMapIteratorrmr>r��_job�_set_lengthrur=r�
_get_tasksr�rrSr�r�rU�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��IMapUnorderedIteratorrmr>r�r�r�rur=rr�rr�rrr�imap_unordered�s0������zPool.imap_unorderedcCs6|��t|||�}|j�|jd|||fgdf�|S)z;
        Asynchronous version of `apply()` method.
        rN)r��ApplyResultrmr>r�)rrSrrTr�r�rUrrrr��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�rgrr��	MapResultrmr>r�r�)
rrSr��mapperr�r�r��extrar�rUrrrr��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)r}�current_threadrhr
rr�r�r�r>rrE)r��cache�	taskqueuerbrar�r�rIrJrKrLr�rNr�r��thread�current_sentinelsrrrr�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)
r}r��iterr?rhr
rrErF�_set�KeyErrorr>rD)
r�r>rJr�r�r��taskseq�
set_lengthrPrVrQ�idxr�rrrr�sN

���
�




��zPool._handle_tasksc	Cs�t��}	z|�}Wnttfyt�d�YdSw|jtkr0|jtks*Jd��t�d�n*|dur:t�d�n |\}}}z
||�	||�Wn	t
yRYnwd}}}q|r�|jtkr�z|�}Wnttfywt�d�YdSw|dur�t�d�qZ|\}}}z
||�	||�Wn	t
y�Ynwd}}}|r�|jtksat|d�r�t�d�ztd	�D]}|j
��s�n|�q�Wnttfy�Ynwt�d
t|�|j�dS)Nrz.result handler got EOFError/OSError -- exitingzThread not in TERMINATEz,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)r}r�rDrCrrErhr
rr�r�r@r�rB�pollr�)rJr?r�r�rPrQrR�objrrrr�=sn

�



��

�

��


��
�zPool._handle_resultsccs0�t|�}	tt�||��}|sdS||fVqr
)r��tupler�islice)rS�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)rrErhr
rr�rnr>r rrrrA�s

�z
Pool.closecCst�d�t|_|��dS)Nzterminating pool)rrErrhr�r rrrr{�s
zPool.terminatecCsht�d�|jtkrtd��|jttfvrtd��|j��|j	��|j
��|jD]}|��q+dS)Nzjoining poolzPool is still runningzIn unknown state)rrErhr
rurrr�r*r�r�rg)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)
rrE�_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 handlerr{zterminating workerszjoining task handlerzjoining result handlerzjoining pool workersr�)rrErrhr>r�r�r�r<r}r�r*r@rzr{�pid)r�r�rIrJr�r��worker_handlerr��result_handlerr�r�rrrr��sJ


�




�


��zPool._terminate_poolcCs|��|Sr
)r�r rrr�	__enter__�szPool.__enter__cCs|��dSr
)r{)r�exc_type�exc_val�exc_tbrrr�__exit__�rz
Pool.__exit__)NNrNNr
)NNN)r)-r"r#r$r7r��staticmethodrar�warnings�warnr
r�r6r|r�r�ryr�r�rjr�r�rrr�r�r�r�r�r�r�r��classmethodrr�r�r�r-rAr{r*r�r�rrrrrrr�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
)
rgr}�Event�_event�next�job_counterr�ro�	_callback�_error_callback)rr�r�r�rrrr�s

zApplyResult.__init__cCs
|j��Sr
)r�is_setr rrr�ready�rzApplyResult.readycCs|��std�|���|jS)Nz{0!r} not ready)rrur=�_successr rrr�
successful�szApplyResult.successfulNcCs|j�|�dSr
)rr�rr�rrrr�r.zApplyResult.waitcCs(|�|�|��st�|jr|jS|j�r
)rrrr�_valuerrrrr?�s
zApplyResult.getcCsZ|\|_|_|jr|jr|�|j�|jr|js|�|j�|j��|j|j=d|_dSr
)	rrrrr�setror�rg�rrRr�rrrr�s


zApplyResult._setr
)
r"r#r$rrrrr?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�rrr�
_chunksize�_number_leftrrror��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)rrrrrror�rrrgr)rrR�success_result�successrUrrrr�)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)rgr}�	Condition�Lock�_condrr
r�ro�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
)
r#r&�popleft�
IndexErrorr'r(rg�
StopIterationrr)rr�r_r r2rrrr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)r#r'r&r�r)�pop�notifyr(ror�rgrrrrr�ms"
�

�"�zIMapIterator._setcCsh|j�'||_|j|jkr"|j��|j|j=d|_Wd�dSWd�dS1s-wYdSr
)r#r(r'r0ror�rg)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.)	r#r&r�r'r0r(ror�rgrrrrr��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`)�dummyra)rbrrTrarrrra�szThreadPool.ProcessNrcCst�||||�dSr
)rr)rr�rKrLrrrr�szThreadPool.__init__cCs,t��|_t��|_|jj|_|jj|_dSr
)rkrlr�r�r>r�r?r�r rrrrj�s


zThreadPool._setup_queuescCs
|jjgSr
)rnrBr rrrr|�rzThreadPool._get_sentinelscCsgSr
rr�rrrr��rZz ThreadPool._get_worker_sentinelscCsBz	|jdd�qtjyYnwt|�D]}|�d�qdS)NTF)�block)r?rk�Emptyr�r>)rIr�r�rRrrrr��s���zThreadPool._help_stuff_finishcCst�|�dSr
)r�r�)rr�r�r�rrrr��szThreadPool._wait_for_updates)NNr)r"r#r$r�rrarrjr|r�r�r�rrrrr�s




)NrNF))�__all__r$rrsrkr}r�r'rrr&rrr�
connectionrr	r
rr�countr
rrrFrr%r,r0rXrG�dictr[�objectrr��AsyncResultr�r�r�rrrrr�<module>sP		
�-@++E
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY