Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib64/python3.7/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/multiprocessing/__pycache__/pool.cpython-37.opt-1.pyc

B

� f�h�@s0ddgZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
mZdZdZ
dZe��Zdd	�Zd
d�ZGdd
�d
e�ZGdd�d�Zdd�ZGdd�de�Zd$dd�Zdd�ZGdd�de�ZGdd�de�ZeZGdd�de�ZGdd �d e�ZGd!d"�d"e�Z Gd#d�de�Z!dS)%�Pool�
ThreadPool�N�)�util)�get_context�TimeoutError�cCstt|��S)N)�list�map)�args�r�9/opt/alt/python37/lib64/python3.7/multiprocessing/pool.py�mapstar+srcCstt�|d|d��S)Nrr)r	�	itertools�starmap)rrrr
�starmapstar.src@seZdZdd�Zdd�ZdS)�RemoteTracebackcCs
||_dS)N)�tb)�selfrrrr
�__init__6szRemoteTraceback.__init__cCs|jS)N)r)rrrr
�__str__8szRemoteTraceback.__str__N)�__name__�
__module__�__qualname__rrrrrr
r5src@seZdZdd�Zdd�ZdS)�ExceptionWithTracebackcCs0t�t|�||�}d�|�}||_d||_dS)N�z

"""
%s""")�	traceback�format_exception�type�join�excr)rr rrrr
r<s
zExceptionWithTraceback.__init__cCst|j|jffS)N)�rebuild_excr r)rrrr
�
__reduce__Asz!ExceptionWithTraceback.__reduce__N)rrrrr"rrrr
r;srcCst|�|_|S)N)r�	__cause__)r rrrr
r!Ds
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�dS)N)�reprr �value�superr$r)rr r&)�	__class__rr
rPs

zMaybeEncodingError.__init__cCsd|j|jfS)Nz(Error sending result: '%s'. Reason: '%s')r&r )rrrr
rUszMaybeEncodingError.__str__cCsd|jj|fS)Nz<%s: %s>)r(r)rrrr
�__repr__YszMaybeEncodingError.__repr__)rrr�__doc__rrr)�
__classcell__rr)r(r
r$Lsr$rFc
Cs�|dk	r(t|t�r|dks(td�|���|j}|j}t|d�rR|j��|j	��|dk	rb||�d}�xP|dks�|�r�||k�r�y
|�}	Wn$t
tfk
r�t�
d�PYnX|	dkr�t�
d�P|	\}
}}}
}yd||
|�f}WnHtk
�r.}z(|�r|tk	�rt||j�}d|f}Wdd}~XYnXy||
||f�WnRtk
�r�}z2t||d�}t�
d	|�||
|d|ff�Wdd}~XYnXd}	}
}}}
}|d7}qjWt�
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�hasattrr,�close�_reader�EOFError�OSErrorr�debug�	Exception�_helper_reraises_exceptionr�
__traceback__r$)�inqueue�outqueue�initializer�initargsZmaxtasksZwrap_exceptionr1r2Z	completed�task�job�i�funcr�kwds�result�e�wrappedrrr
�worker]sJ





$rHcCs|�dS)z@Pickle-able helper function for use by _guarded_task_generation.Nr)Zexrrr
r:�sr:c@s,eZdZdZdZdd�Zd>dd�Zd	d
�Zdd�Zd
d�Z	dd�Z
difdd�Zd?dd�Zd@dd�Z
dAdd�Zdd�ZdBdd�ZdCdd�Zdiddfd d!�ZdDd"d#�ZdEd$d%�Zed&d'��Zed(d)��Zed*d+��Zed,d-��Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zed6d7��Zed8d9��Z d:d;�Z!d<d=�Z"dS)FrzS
    Class which supports an async version of applying functions to arguments.
    TcOs|jj||�S)N)�_ctx�Process)rrrDrrr
rJ�szPool.ProcessNrcCsl|pt�|_|��t��|_i|_t|_||_	||_
||_|dkrPt�
�pNd}|dkr`td��|dk	rxt|�sxtd��||_g|_|��tjtj|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!|jfdd�|_&dS)Nrz&Number of processes must be at least 1zinitializer must be a callable)�targetrT�)rZexitpriority)'rrI�
_setup_queues�queue�SimpleQueue�
_taskqueue�_cache�RUN�_state�_maxtasksperchild�_initializer�	_initargs�os�	cpu_count�
ValueError�callable�	TypeError�
_processes�_pool�_repopulate_pool�	threadingZThreadr�_handle_workers�_worker_handler�daemon�start�
_handle_tasks�
_quick_put�	_outqueue�
_task_handler�_handle_results�
_quick_get�_result_handlerrZFinalize�_terminate_pool�_inqueue�
_terminate)r�	processesr>r?Zmaxtasksperchild�contextrrr
r�sT




z
Pool.__init__cCsZd}xPttt|j���D]:}|j|}|jdk	rt�d|�|��d}|j|=qW|S)z�Cleanup after any worker processes which have exited due to reaching
        their specified lifetime.  Returns True if any workers were cleaned up.
        FNzcleaning up worker %dT)�reversed�range�lenr]�exitcoderr8r)rZcleanedrBrHrrr
�_join_exited_workers�s

zPool._join_exited_workersc	Cs|xvt|jt|j��D]^}|jt|j|j|j|j	|j
|jfd�}|j�|�|j
�dd�|_
d|_|��t�d�qWdS)z�Bring the number of pool processes up to the specified number,
        for use after reaping workers which have exited.
        )rKrrJZ
PoolWorkerTzadded workerN)rqr\rrr]rJrHrlrfrUrVrT�_wrap_exception�append�name�replacerbrcrr8)rrB�wrrr
r^�szPool._repopulate_poolcCs|��r|��dS)zEClean up any exited workers and start replacements for them.
        N)rtr^)rrrr
�_maintain_pool�szPool._maintain_poolcCs4|j��|_|j��|_|jjj|_|jjj|_	dS)N)
rIrOrlrfr,�sendrer5�recvri)rrrr
rM�szPool._setup_queuescCs|�|||���S)zT
        Equivalent of `func(*args, **kwds)`.
        Pool must be running.
        )�apply_asyncr2)rrCrrDrrr
�applysz
Pool.applycCs|�||t|���S)zx
        Apply `func` to each element in `iterable`, collecting the results
        in a list that is returned.
        )�
_map_asyncrr2)rrC�iterable�	chunksizerrr
r
szPool.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).
        )rrr2)rrCr�r�rrr
rszPool.starmapcCs|�||t|||�S)z=
        Asynchronous version of `starmap()` method.
        )rr)rrCr�r��callback�error_callbackrrr
�
starmap_asyncszPool.starmap_asyncc
csny0d}x&t|�D]\}}||||fifVqWWn8tk
rh}z||dt|fifVWdd}~XYnXdS)z�Provides a generator of tasks for imap and imap_unordered with
        appropriate handling for iterables which throw exceptions during
        iteration.���rN)�	enumerater9r:)rZ
result_jobrCr�rB�xrFrrr
�_guarded_task_generationszPool._guarded_task_generationrcCs�|jtkrtd��|dkrFt|j�}|j�|�|j||�|j	f�|S|dkr\td�
|���t�|||�}t|j�}|j�|�|jt
|�|j	f�dd�|D�SdS)zP
        Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
        zPool not runningrzChunksize must be 1+, not {0:n}css|]}|D]
}|Vq
qdS)Nr)�.0�chunk�itemrrr
�	<genexpr>EszPool.imap.<locals>.<genexpr>N)rSrRrY�IMapIteratorrQrPr1r��_job�_set_lengthr0r�
_get_tasksr)rrCr�r�rE�task_batchesrrr
�imap)s(




z	Pool.imapcCs�|jtkrtd��|dkrFt|j�}|j�|�|j||�|j	f�|S|dkr\td�
|���t�|||�}t|j�}|j�|�|jt
|�|j	f�dd�|D�SdS)zL
        Like `imap()` method but ordering of results is arbitrary.
        zPool not runningrzChunksize must be 1+, not {0!r}css|]}|D]
}|Vq
qdS)Nr)r�r�r�rrr
r�bsz&Pool.imap_unordered.<locals>.<genexpr>N)rSrRrY�IMapUnorderedIteratorrQrPr1r�r�r�r0rr�r)rrCr�r�rEr�rrr
�imap_unorderedGs&




zPool.imap_unorderedcCsB|jtkrtd��t|j||�}|j�|jd|||fgdf�|S)z;
        Asynchronous version of `apply()` method.
        zPool not runningrN)rSrRrY�ApplyResultrQrPr1r�)rrCrrDr�r�rErrr
r}ds

zPool.apply_asynccCs|�||t|||�S)z9
        Asynchronous version of `map()` method.
        )rr)rrCr�r�r�r�rrr
�	map_asyncoszPool.map_asyncc
Cs�|jtkrtd��t|d�s$t|�}|dkrTtt|�t|j�d�\}}|rT|d7}t|�dkrdd}t�	|||�}t
|j|t|�||d�}	|j�
|�|	j||�df�|	S)zY
        Helper function to implement map, starmap and their async counterparts.
        zPool not running�__len__N�rr)r�)rSrRrYr3r	�divmodrrr]rr��	MapResultrQrPr1r�r�)
rrCr�Zmapperr�r�r�Zextrar�rErrr
rws&

zPool._map_asynccCsTt��}x0|jtks$|jr8|jtkr8|��t�d�q
W|j	�
d�t�d�dS)Ng�������?zworker handler exiting)
r_�current_threadrSrRrQ�	TERMINATErz�time�sleeprPr1rr8)�pool�threadrrr
r`�szPool._handle_workersc

Csjt��}x�t|jd�D]�\}}d}z�x�|D]�}|jr@t�d�Py||�Wq*tk
r�}	zB|dd�\}
}y||
�|d|	f�Wnt	k
r�YnXWdd}	~	XYq*Xq*W|r�t�d�|r�|dnd}||d�wPWdd}}}
XqWt�d�y:t�d�|�
d�t�d	�x|D]}|d��q&WWn tk
�rZt�d
�YnXt�d�dS)Nz'task handler found thread._state != RUNrFzdoing 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��iterr2rSrr8r9�_set�KeyErrorr1r7)
�	taskqueuer1r=r��cacher�ZtaskseqZ
set_lengthr@rFrA�idx�prrr
rd�sB







zPool._handle_tasksc	Cs�t��}x�y
|�}Wn"ttfk
r6t�d�dSX|jrJt�d�P|dkr^t�d�P|\}}}y||�||�Wntk
r�YnXd}}}q
Wx�|�r>|jt	k�r>y
|�}Wn"ttfk
r�t�d�dSX|dk�r�t�d�q�|\}}}y||�||�Wntk
�r.YnXd}}}q�Wt
|d��r�t�d�y,x&td�D]}|j�
��stP|��qbWWnttfk
�r�YnXt�dt|�|j�dS)	Nz.result handler got EOFError/OSError -- exitingz,result handler found thread._state=TERMINATEzresult handler got sentinelz&result handler ignoring extra sentinelr5z"ensuring that outqueue is not full�
z7result handler exiting: len(cache)=%s, thread._state=%s)r_r�r7r6rr8rSr�r�r�r3rqr5�pollrr)r=r2r�r�r@rArB�objrrr
rh�sZ










zPool._handle_resultsccs4t|�}x&tt�||��}|s"dS||fVq
WdS)N)r��tupler�islice)rC�it�sizer�rrr
r�szPool._get_taskscCstd��dS)Nz:pool objects cannot be passed between processes or pickled)�NotImplementedError)rrrr
r"szPool.__reduce__cCs&t�d�|jtkr"t|_t|j_dS)Nzclosing pool)rr8rSrR�CLOSEra)rrrr
r4s

z
Pool.closecCs$t�d�t|_t|j_|��dS)Nzterminating pool)rr8r�rSrarm)rrrr
�	terminate s
zPool.terminatecCsnt�d�|jtkrtd��n|jttfkr4td��|j��|j	��|j
��x|jD]}|��qZWdS)Nzjoining poolzPool is still runningzIn unknown state)rr8rSrRrYr�r�rarrgrjr])rr�rrr
r&s





z	Pool.joincCsDt�d�|j��x*|��r>|j��r>|j��t�	d�qWdS)Nz7removing tasks from inqueue until task handler finishedr)
rr8Z_rlock�acquire�is_aliver5r�r|r�r�)r<�task_handlerr�rrr
�_help_stuff_finish2s



zPool._help_stuff_finishc	
CsJt�d�t|_t|_t�d�|�||t|��|��sNt|�dkrNtd��t|_|�d�t�d�t	�
�|k	r||��|r�t|dd�r�t�d�x|D]}	|	j
dkr�|	��q�Wt�d�t	�
�|k	r�|��t�d	�t	�
�|k	r�|��|�rFt|dd��rFt�d
�x0|D](}	|	���rt�d|	j�|	���qWdS)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 workerszcleaning up worker %d)rr8r�rSr�rrr�r/r1r_r�rr3rsr��pid)
�clsr�r<r=r�Zworker_handlerr�Zresult_handlerr�r�rrr
rk;s<











zPool._terminate_poolcCs|S)Nr)rrrr
�	__enter__kszPool.__enter__cCs|��dS)N)r�)r�exc_typeZexc_valZexc_tbrrr
�__exit__nsz
Pool.__exit__)NNrNN)N)N)NNN)r)r)NNN)NNN)#rrrr*rurJrrtr^rzrMr~r
rr�r�r�r�r}r�r�staticmethodr`rdrhr�r"r4r�rr��classmethodrkr�r�rrrr
r�sF
8








.<		0c@s@eZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�ZdS)r�cCs4t��|_tt�|_||_||_||_|||j<dS)N)	r_ZEvent�_event�next�job_counterr�rQ�	_callback�_error_callback)rr�r�r�rrr
rws

zApplyResult.__init__cCs
|j��S)N)r�Zis_set)rrrr
�readyszApplyResult.readycCs|��std�|���|jS)Nz{0!r} not ready)r�rYr0�_success)rrrr
�
successful�szApplyResult.successfulNcCs|j�|�dS)N)r��wait)r�timeoutrrr
r��szApplyResult.waitcCs,|�|�|��st�|jr"|jS|j�dS)N)r�r�rr��_value)rr�rrr
r2�s
zApplyResult.getcCsT|\|_|_|jr$|jr$|�|j�|jr<|js<|�|j�|j��|j|j=dS)N)r�r�r�r�r��setrQr�)rrBr�rrr
r��s
zApplyResult._set)N)N)	rrrrr�r�r�r2r�rrrr
r�us

	r�c@seZdZdd�Zdd�ZdS)r�cCsftj||||d�d|_dg||_||_|dkrLd|_|j��||j=n||t	||�|_dS)N)r�Tr)
r�rr�r��
_chunksize�_number_leftr�r�r��bool)rr�r��lengthr�r�rrr
r�s


zMapResult.__init__cCs�|jd8_|\}}|rp|jrp||j||j|d|j�<|jdkr�|jrZ|�|j�|j|j=|j��nF|s�|jr�d|_||_|jdkr�|j	r�|�	|j�|j|j=|j��dS)NrrF)
r�r�r�r�r�rQr�r�r�r�)rrBZsuccess_result�successrErrr
r��s"





zMapResult._setN)rrrrr�rrrr
r��s
r�c@s:eZdZdd�Zdd�Zddd�ZeZdd	�Zd
d�ZdS)
r�cCsJt�t���|_tt�|_||_t�	�|_
d|_d|_i|_
|||j<dS)Nr)r_Z	ConditionZLock�_condr�r�r�rQ�collections�deque�_items�_index�_length�	_unsorted)rr�rrr
r�s

zIMapIterator.__init__cCs|S)Nr)rrrr
�__iter__�szIMapIterator.__iter__NcCs�|j��y|j��}Wnntk
r�|j|jkr8td�|j�|�y|j��}Wn,tk
r~|j|jkrttd�td�YnXYnXWdQRX|\}}|r�|S|�dS)N)	r�r��popleft�
IndexErrorr�r��
StopIterationr�r)rr�r�r�r&rrr
r��s"zIMapIterator.nextc	Cs�|j��|j|krr|j�|�|jd7_x8|j|jkrd|j�|j�}|j�|�|jd7_q.W|j��n
||j|<|j|jkr�|j|j	=WdQRXdS)Nr)
r�r�r�rvr��pop�notifyr�rQr�)rrBr�rrr
r��s

zIMapIterator._setc	Cs<|j�,||_|j|jkr.|j��|j|j=WdQRXdS)N)r�r�r�r�rQr�)rr�rrr
r�s

zIMapIterator._set_length)N)	rrrrr�r��__next__r�r�rrrr
r��s

r�c@seZdZdd�ZdS)r�c	CsP|j�@|j�|�|jd7_|j��|j|jkrB|j|j=WdQRXdS)Nr)r�r�rvr�r�r�rQr�)rrBr�rrr
r�
s
zIMapUnorderedIterator._setN)rrrr�rrrr
r�sr�c@s:eZdZdZedd��Zddd�Zdd	�Zed
d��ZdS)
rFcOsddlm}|||�S)Nr)rJ)ZdummyrJ)rrDrJrrr
rJszThreadPool.ProcessNrcCst�||||�dS)N)rr)rrnr>r?rrr
r!szThreadPool.__init__cCs,t��|_t��|_|jj|_|jj|_dS)N)rNrOrlrfr1rer2ri)rrrr
rM$s


zThreadPool._setup_queuescCsNyx|jdd�qWWntjk
r,YnXxt|�D]}|�d�q8WdS)NF)�block)r2rNZEmptyrqr1)r<r�r�rBrrr
r�*szThreadPool._help_stuff_finish)NNr)	rrrrur�rJrrMr�rrrr
rs

)NrNF)"�__all__r_rNrr�rWr�rrrrrrRr�r��countr�rrr9rrr!r$rHr:�objectrr�ZAsyncResultr�r�r�rrrrr
�<module>
s@	
,f')@

Hacked By AnonymousFox1.0, Coded By AnonymousFox