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-2.pyc

B

YI~d�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!cs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�MaybeEncodingErrorcs.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__)rrrrrr)�
__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_exceptionr0r1Z	completed�task�job�i�funcr�kwds�result�e�wrappedrrr
�worker]sJ





$rGcCs|�dS)Nr)Zexrrr
r9�sr9c@s(eZdZdZdd�Zd=dd�Zdd	�Zd
d�Zdd
�Zdd�Z	difdd�Z
d>dd�Zd?dd�Zd@dd�Z
dd�ZdAdd�ZdBdd�Zdiddfdd �ZdCd!d"�ZdDd#d$�Zed%d&��Zed'd(��Zed)d*��Zed+d,��Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zed5d6��Zed7d8��Zd9d:�Z d;d<�Z!dS)ErTcOs|jj||�S)N)�_ctx�Process)rrrCrrr
rI�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)'rrH�
_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)NFzcleaning up worker %dT)�reversed�range�lenr\�exitcoderr7r)rZcleanedrArGr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)N)rJrrIZ
PoolWorkerTzadded worker)rpr[rqr\rIrGrkrerTrUrS�_wrap_exception�append�name�replacerarbrr7)rrA�wrrr
r]�szPool._repopulate_poolcCs|��r|��dS)N)rsr])rrrr
�_maintain_pool�szPool._maintain_poolcCs4|j��|_|j��|_|jjj|_|jjj|_	dS)N)
rHrNrkrer+�sendrdr4�recvrh)rrrr
rL�szPool._setup_queuescCs|�|||���S)N)�apply_asyncr1)rrBrrCrrr
�applysz
Pool.applycCs|�||t|���S)N)�
_map_asyncrr1)rrB�iterable�	chunksizerrr
r
szPool.mapcCs|�||t|���S)N)r~rr1)rrBrr�rrr
rszPool.starmapcCs|�||t|||�S)N)r~r)rrBrr��callback�error_callbackrrr
�
starmap_asyncszPool.starmap_asyncc
csny0d}x&t|�D]\}}||||fifVqWWn8tk
rh}z||dt|fifVWdd}~XYnXdS)N���r)�	enumerater8r9)rZ
result_jobrBrrA�xrEr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)NzPool not runningrzChunksize must be 1+, not {0:n}css|]}|D]
}|Vq
qdS)Nr)�.0�chunk�itemrrr
�	<genexpr>EszPool.imap.<locals>.<genexpr>)rRrQrX�IMapIteratorrPrOr0r��_job�_set_lengthr/r�
_get_tasksr)rrBrr�rD�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)NzPool 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>)rRrQrX�IMapUnorderedIteratorrPrOr0r�r�r�r/rr�r)rrBrr�rDr�rrr
�imap_unorderedGs&




zPool.imap_unorderedcCsB|jtkrtd��t|j||�}|j�|jd|||fgdf�|S)NzPool not runningr)rRrQrX�ApplyResultrPrOr0r�)rrBrrCr�r�rDrrr
r|ds

zPool.apply_asynccCs|�||t|||�S)N)r~r)rrBrr�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)NzPool not running�__len__�rr)r�)rRrQrXr2r	�divmodrqr\rr��	MapResultrPrOr0r�r�)
rrBrZmapperr�r�r�Zextrar�rDrrr
r~ws&

zPool._map_asynccCsTt��}x0|jtks$|jr8|jtkr8|��t�d�q
W|j	�
d�t�d�dS)Ng�������?zworker handler exiting)
r^�current_threadrRrQrP�	TERMINATEry�time�sleeprOr0rr7)�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��iterr1rRrr7r8�_set�KeyErrorr0r6)
�	taskqueuer0r<r��cacher�ZtaskseqZ
set_lengthr?rEr@�idx�prrr
rc�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 sentinelr4z"ensuring that outqueue is not full�
z7result handler exiting: len(cache)=%s, thread._state=%s)r^r�r6r5rr7rRr�r�r�r2rpr4�pollrq)r<r1r�r�r?r@rA�objrrr
rg�sZ










zPool._handle_resultsccs4t|�}x&tt�||��}|s"dS||fVq
WdS)N)r��tupler�islice)rB�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)rr7rRrQ�CLOSEr`)rrrr
r3s

z
Pool.closecCs$t�d�t|_t|j_|��dS)Nzterminating pool)rr7r�rRr`rl)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)rr7rRrQrXr�r�r`rrfrir\)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)
rr7Z_rlock�acquire�is_aliver4r�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)rr7r�rRr�rqr�r.r0r^r�rr2rrr��pid)
�clsr�r;r<r�Zworker_handlerr�Zresult_handlerr�r�rrr
rj;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)"rrrrtrIrrsr]ryrLr}r
rr�r�r�r�r|r�r~�staticmethodr_rcrgr�r"r3r�rr��classmethodrjr�r�rrrr
r�sD
8








.<		0c@s@eZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�ZdS)r�cCs4t��|_tt�|_||_||_||_|||j<dS)N)	r^ZEvent�_event�next�job_counterr�rP�	_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�rXr/�_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
r1�s
zApplyResult.getcCsT|\|_|_|jr$|jr$|�|j�|jr<|js<|�|j�|j��|j|j=dS)N)r�r�r�r�r��setrPr�)rrAr�rrr
r��s
zApplyResult._set)N)N)	rrrrr�r�r�r1r�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�rPr�r�r�r�)rrAZsuccess_result�successrDr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�rP�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�rur��pop�notifyr�rPr�)rrAr�rrr
r��s

zIMapIterator._setc	Cs<|j�,||_|j|jkr.|j��|j|j=WdQRXdS)N)r�r�r�r�rPr�)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�rur�r�r�rPr�)rrAr�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)rI)ZdummyrI)rrCrIrrr
rIszThreadPool.ProcessNrcCst�||||�dS)N)rr)rrmr=r>rrr
r!szThreadPool.__init__cCs,t��|_t��|_|jj|_|jj|_dS)N)rMrNrkrer0rdr1rh)rrrr
rL$s


zThreadPool._setup_queuescCsNyx|jdd�qWWntjk
r,YnXxt|�D]}|�d�q8WdS)NF)�block)r1rMZEmptyrpr0)r;r�r�rArrr
r�*szThreadPool._help_stuff_finish)NNr)	rrrrtr�rIrrLr�rrrr
rs

)NrNF)"�__all__r^rMrr�rVr�rrrrrrQr�r��countr�rrr8rrr!r$rGr9�objectrr�ZAsyncResultr�r�r�rrrrr
�<module>
s@	
,f')@

Hacked By AnonymousFox1.0, Coded By AnonymousFox