HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/local/lib/python3.9/site-packages/billiard/__pycache__/pool.cpython-39.pyc
a

X>h��@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZmZddlmZddlmZmZmZmZmZddlmZmZmZdd	lmZdd
lmZddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddlm(Z(dd
l)m*Z*m+Z+ddlm,Z,m-Z-m.Z.dZ/ej0ddkZ1e�2�dk�rRddl3m4Z5eZ6nddlm7Z5ej6Z6z
ej8Z8Wne9�y�dZ8Yn0ej0dk�r�ej:Z;nej;Z;dZ<dZ=dZ>dZ?dZ@dZAdZBdZCdZDdZEdZFeGedd�ZHdZIeGedd�ZDdZJdZKe�L�ZMejNZNdd�ZOd d!�ZPd"d#�ZQd$d%�ZRdHd&d'�ZSGd(d)�d)e;�ZTGd*d+�d+eU�ZVGd,d-�d-eU�ZWd.d/�ZXGd0d1�d1�ZYGd2d3�d3e�ZZGd4d5�d5eZ�Z[Gd6d7�d7eZ�Z\Gd8d9�d9eZ�Z]Gd:d;�d;eZ�Z^Gd<d=�d=�Z_Gd>d?�d?�Z`Gd@dA�dAe`�ZaGdBdC�dC�ZbGdDdE�dEeb�ZcGdFdG�dGe_�ZddS)I�N)�deque)�partial�)�	cpu_count�get_context)�util)�TERM_SIGNAL�human_status�pickle_loads�
reset_signals�
restart_state)�	get_errno�mem_rss�send_offset)�
ExceptionInfo)�DummyProcess)�CoroStop�RestartFreqExceeded�SoftTimeLimitExceeded�
Terminated�TimeLimitExceeded�TimeoutError�WorkerLostError��	monotonic��Queue�Empty)�Finalize�debug�warningzEchild process exiting after exceeding memory limit ({0}KiB / {1}KiB)
��Windows)�kill_processtree)�killg _�B)r!r!����SIGUSR1g$@�EX_OKi,皙�����?cCs<z
|j}Wnty d}Yn0|dur8tt|���S|S�N)r�AttributeErrorr�fileno)�
connectionZnative�r/�7/usr/local/lib/python3.9/site-packages/billiard/pool.py�_get_send_offsetxs

r1cCstt|��Sr+)�list�map��argsr/r/r0�mapstar�sr6cCstt�|d|d��S)Nrr)r2�	itertools�starmapr4r/r/r0�starmapstar�sr9cOs t��j|g|�Ri|��dSr+)rZ
get_logger�error)�msgr5�kwargsr/r/r0r:�sr:cCs|t��ur|�|�dSr+)�	threading�current_thread�stop)�thread�timeoutr/r/r0�stop_if_not_current�srBc@sbeZdZdZdd�Zer<ddd�Zdd	�Zd
d�Zdd
�Z	n"ddd�Zdd	�Zdd�Zdd
�Z	dS)�LaxBoundedSemaphorez^Semaphore that checks that # release is <= # acquires,
    but ignores if # releases >= value.cCs|jd8_|��dS�Nr)�_initial_value�acquire��selfr/r/r0�shrink�szLaxBoundedSemaphore.shrinkrNcCst�||�||_dSr+��
_Semaphore�__init__rE�rH�value�verboser/r/r0rL�szLaxBoundedSemaphore.__init__cCsP|j�6|jd7_|jd7_|j��Wd�n1sB0YdSrD)�_condrE�_value�notifyrGr/r/r0�grow�szLaxBoundedSemaphore.growcCsP|j}|�2|j|jkr.|jd7_|��Wd�n1sB0YdSrD)rPrQrE�
notify_all�rHZcondr/r/r0�release�s
zLaxBoundedSemaphore.releasecCs|j|jkrt�|�qdSr+)rQrErKrVrGr/r/r0�clear�szLaxBoundedSemaphore.clearcCst�|||�||_dSr+rJrMr/r/r0rL�scCsR|j}|�4|jd7_|jd7_|��Wd�n1sD0YdSrD)�_Semaphore__condrE�_Semaphore__valuerRrUr/r/r0rS�s
cCsP|j}|�2|j|jkr.|jd7_|��Wd�n1sB0YdSrD)rXrYrE�	notifyAllrUr/r/r0rV�s
cCs|j|jkrt�|�qdSr+)rYrErKrVrGr/r/r0rW�s)rN)rN)
�__name__�
__module__�__qualname__�__doc__rI�PY3rLrSrVrWr/r/r/r0rC�s


rCcs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�MaybeEncodingErrorzVWraps possible unpickleable errors, so they can be
    safely sent through the socket.cs*t|�|_t|�|_t��|j|j�dSr+)�repr�excrN�superrL)rHrbrN��	__class__r/r0rL�s

zMaybeEncodingError.__init__cCsd|jjt|�fS)Nz<%s: %s>)rer[�strrGr/r/r0�__repr__�szMaybeEncodingError.__repr__cCsd|j|jfS)Nz)Error sending result: '%r'. Reason: '%r'.)rNrbrGr/r/r0�__str__�s�zMaybeEncodingError.__str__)r[r\r]r^rLrgrh�
__classcell__r/r/rdr0r`�sr`c@seZdZdZdS)�
WorkersJoinedzAll workers have terminated.N)r[r\r]r^r/r/r/r0rj�srjcCs
t��dSr+)r)�signum�framer/r/r0�soft_timeout_sighandler�srmc
@s�eZdZddd�Zdd�Zdd	�Zd
d�Zddd
�Zdd�Zdd�Z	e
edfdd�Zdd�Z
dd�Zdd�Zefdd�Zdd�ZdS) �WorkerNr/Tc

Csz|dus t|�tkr|dks J�||_||_||_||_||_||_|	|_||||_	|_
|_|
|_||_
|�|�dS�Nr)�type�int�initializer�initargs�maxtasks�max_memory_per_child�	_shutdown�on_exit�
sigprotection�inq�outq�synq�wrap_exception�on_ready_counter�contribute_to_object)
rHryrzr{rrrsrt�sentinelrwrxr|rur}r/r/r0rL�s zWorker.__init__cCs�|j|j|j|_|_|_|jj��|_|jj��|_|jrj|jj��|_|jj��|_	t
|jj�|_nd|_|_	|_|jjj
|_|jjj|_t
|jj�|_|Sr+)ryrzr{�_writerr-�inqW_fd�_readerZoutqR_fdZsynqR_fd�synqW_fdr1Zsend_syn_offsetZ_send_syn_offset�send�
_quick_put�recv�
_quick_getZsend_job_offset)rH�objr/r/r0r~�szWorker.contribute_to_objectc
Cs:|j|j|j|j|j|j|j|j|j|j	|j
|j|jffSr+)
reryrzr{rrrsrtrvrwrxr|rur}rGr/r/r0�
__reduce__
s�zWorker.__reduce__cs�tj�dg�d��fdd�	}|t_t��}|��|��|j|d�ztzt�|j|d��WnFty�}z.t	d||dd�|�
|�d|�WYd}~n
d}~00W|�
|�dd�n|�
|�dd�0dS)	Ncs|�d<�|�Sror/)�status��_exitZ	_exitcoder/r0�exitszWorker.__call__.<locals>.exit��pidzPool process %r error: %rr��exc_infor)N)�sysr��os�getpid�_make_child_methods�
after_fork�
on_loop_start�workloop�	Exceptionr:�_do_exit)rHr�r�rbr/r�r0�__call__s*zWorker.__call__c	Cs~|dur|rtnt}|jdur*|�||�tjdkrpz,|j�t||ff�t�	d�Wt
�|�qzt
�|�0n
t
�|�dS)N�win32r)�
EX_FAILUREr)rwr��platformrz�put�DEATH�time�sleepr�r�)rHr��exitcoderbr/r/r0r�+s

zWorker._do_exitcCsdSr+r/�rHr�r/r/r0r�;szWorker.on_loop_startcCs|Sr+r/)rH�resultr/r/r0�prepare_result>szWorker.prepare_resultc
s<|p
t��}�jj}�j}�j}�j}�jp.d}�j}	�j	}
�j
���fdd�}d}�z�|dusp|�r�||k�r�|
�}
|
rX|
\}}|tks�J�|\}}}}}|t|||�||ff��r�||�}|s�qXzd|	||i|���f}Wnt
y�dt�f}Yn0z|t||||ff�Wntt
�y�}zZt��\}}}z:t||d�}tt||f�}|t||d|f|ff�W~n~0WYd}~n
d}~00|d7}|dkrXt�}|dk�r�td�|dkrX||krXtt�||��tW�j|d�SqX|d	|�|�r||k�rtntW�j|d�StW�j|d�S�j|d�0dS)
Nrcs`d}|dkr$td|�jj��dd���}|rR|\}}|tkrBdS|tksNJ�dS|d7}qdS)Nr�<z(!!!WAIT FOR ACK TIMEOUT: job:%r fd:%r!!!rr�FT)r:r{r�r-�NACK�ACK)Zjid�i�req�type_r5�Z
_wait_for_synrHr/r0�wait_for_synMs�z%Worker.workloop.<locals>.wait_for_synTFrz'worker unable to determine memory usage)�	completedzworker exiting after %d tasks)r�r�rzr�r�r�rtrur��wait_for_jobr��TASKr�r�r�READYr�r�r`rr:r �MAXMEM_USED_FMT�format�
EX_RECYCLE�_ensure_messages_consumedr�r))rHr�nowr�r�r�r�rtrur�r�r�r�r�r��args_�jobr��funr5r<Zconfirmr�rb�_�tb�wrapped�einfoZused_kbr/r�r0r�Asv
�
��
��zWorker.workloopcCsJ|js
dStt�D]*}|jj|kr2td|�dSt�t�qtd�dS)zr Returns true if all messages sent out have been received and
        consumed within a reasonable amount of time Fz*ensured messages consumed after %d retriesTz<could not ensure all messages were consumed prior to exiting)	r}�range�)GUARANTEE_MESSAGE_CONSUMPTION_RETRY_LIMITrNrr�r��,GUARANTEE_MESSAGE_CONSUMPTION_RETRY_INTERVALr )rHr��retryr/r/r0r��s
z Worker._ensure_messages_consumedcCs�t|jd�r|jj��t|jd�r0|jj��|jdurF|j|j�t|j	d�t
durft�t
t�zt�tj
tj�Wnty�Yn0dS)Nr�r�)�full)�hasattrryr��closerzr�rrrsrrx�SIG_SOFT_TIMEOUT�signalrm�SIGINT�SIG_IGNr,rGr/r/r0r��s
zWorker.after_forkcs`|j�t|d�rP|jj�t|d�r@|jr@|j�tf�fdd�	}q\��fdd�}n�fdd�}|S)Nr��get_payloadcsd|���fS�NTr/)rA�loads)r�r/r0�_recv�sz'Worker._make_recv_method.<locals>._recvcs�|�rd��fSdS�NT�FNr/�rA)�_poll�getr/r0r��s
cs,zd�|d�fWStjy&YdS0dS�NTr�r�rr�)r�r/r0r��s)r�r�r��pollr�r
)rH�connr�r/)r�r�r�r0�_make_recv_method�s
zWorker._make_recv_methodcCs*|�|j�|_|jr |�|j�nd|_dSr+)�_make_protected_receiveryr�r{r�)rHr�r/r/r0r��s
��zWorker._make_child_methodscs2|�|��|jr|jjnd�tf��fdd�	}|S)Nc
s��r��r|d�tt��z�d�\}}|s2WdSWn\ttfy�}z@t|�tjkrdWYd}~dS|dt|�j�tt	��WYd}~n
d}~00|dur�|d�tt	��|S)Nzworker got sentinel -- exiting��?zworker got %s -- exiting)
�
SystemExitr)�EOFError�IOErrorr
�errnoZEINTRrpr[r�)r�readyr�rb�Z_receiveZshould_shutdownr/r0�receive�s 

z/Worker._make_protected_receive.<locals>.receive)r�rv�is_setr)rHr�r�r/r�r0r��s
zWorker._make_protected_receive)
NNr/NNNTTNN)N)r[r\r]rLr~r�r�r�r�r�rrr�r�r�r�r
r�r�r/r/r/r0rn�s"�

MrncsNeZdZdd�Zdd�Z�fdd�Zdd�Zdd
d�Zdd
�Zdd�Z	�Z
S)�
PoolThreadcOs t�|�t|_d|_d|_dS�NFT)rrL�RUN�_state�_was_started�daemon�rHr5r<r/r/r0rL�s
zPoolThread.__init__c
Cs�z
|��WStyZ}z8tdt|�j|dd�tt��t�t	�
�WYd}~nLd}~0ty�}z,tdt|�j|dd�t�d�WYd}~n
d}~00dS)NzThread %r crashed: %rrr�)
�bodyrr:rpr[�_killr�r�rr�r�r�r��rHrbr/r/r0�run�s
��zPoolThread.runcs d|_tt|�j|i|��dSr�)r�rcr��startr�rdr/r0r�szPoolThread.startcCsdSr+r/rGr/r/r0�on_stop_not_startedszPoolThread.on_stop_not_startedNcCs |jr|�|�dS|��dSr+)r��joinr��rHrAr/r/r0r?
s
zPoolThread.stopcCs
t|_dSr+)�	TERMINATEr�rGr/r/r0�	terminateszPoolThread.terminatecCs
t|_dSr+)�CLOSEr�rGr/r/r0r�szPoolThread.close)N)r[r\r]rLr�r�r�r?r�r�rir/r/rdr0r��s

r�cs$eZdZ�fdd�Zdd�Z�ZS)�
Supervisorcs||_t���dSr+)�poolrcrL)rHr�rdr/r0rLszSupervisor.__init__cCs�td�t�d�|j}z~|j}td|jd�|_td�D]*}|jtkr:|jtkr:|�	�t�d�q:||_|jtkr�|jtkr�|�	�t�d�qlWn$t
y�|��|���Yn0td�dS)Nzworker handler startingg�������?�
rr*zworker handler exiting)
rr�r�r�r�
_processesr�r�r��_maintain_poolrr�r�)rHr�Z
prev_stater�r/r/r0r�s&
zSupervisor.body)r[r\r]rLr�rir/r/rdr0r�sr�cs4eZdZ�fdd�Zdd�Zdd�Zdd�Z�ZS)	�TaskHandlercs,||_||_||_||_||_t���dSr+)�	taskqueuer��outqueuer��cachercrL)rHr�r�r�r�r�rdr/r0rL>szTaskHandler.__init__c

Cs~|j}|j}|j}t|jd�D�]H\}}d}d}z�t|�D]�\}}|jrTtd�q�z||�Wq:ty�td�Yq�Yq:t	y�|dd�\}}	z||�
|	dt�f�Wnty�Yn0Yq:0q:|r�td�||d�WqW�qrWqt	�yf|�r|dd�nd\}}	||v�rF||�
|	ddt�f�|�rbt
�d�||d�Yq0qtd	�|��dS)
N���z'task handler found thread._state != RUNzcould not put task on queuer%Fzdoing set_length()r)rrztask handler got sentinel)r�r�r��iterr��	enumerater�rr�r��_setr�KeyErrorr�tell_others)
rHr�r�r�ZtaskseqZ
set_length�taskr�r��indr/r/r0r�FsH


zTaskHandler.bodycCsj|j}|j}|j}z0td�|�d�td�|D]}|d�q2Wnty\td�Yn0td�dS)Nz/task handler sending sentinel to result handlerz(task handler sending sentinel to workersz/task handler got IOError when sending sentinelsztask handler exiting)r�r�r�rr�)rHr�r�r��pr/r/r0rps
zTaskHandler.tell_otherscCs|��dSr+)rrGr/r/r0r��szTaskHandler.on_stop_not_started)r[r\r]rLr�rr�rir/r/rdr0r�<s*r�csTeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
�ZS)�TimeoutHandlercs,||_||_||_||_d|_t���dSr+)�	processesr��t_soft�t_hard�_itrcrL)rHrr�rrrdr/r0rL�szTimeoutHandler.__init__cst�fdd�t|j�D�d�S)Nc3s$|]\}}|j�kr||fVqdSr+r���.0r��procr�r/r0�	<genexpr>�s
�z1TimeoutHandler._process_by_pid.<locals>.<genexpr>�NN)�nextr�rr�r/r�r0�_process_by_pid�s
��zTimeoutHandler._process_by_pidc
Csxtd|�|�|j�\}}|s"dS|jdd�zt|jt�Wn4tyr}zt|�tj	kr^�WYd}~n
d}~00dS)Nzsoft time limit exceeded for %rT��soft)
rr�_worker_pid�handle_timeoutr�r��OSErrorr
r��ESRCH)rHr��process�_indexrbr/r/r0�on_soft_timeout�s
zTimeoutHandler.on_soft_timeoutcCsz|��rdStd|�zt|j��Wn&tyJ|�|jdt�f�Yn0|�|j�\}}|j	dd�|rv|�
|�dS)Nzhard time limit exceeded for %rFr)r�rr�_timeoutr��_jobrrrr�_trywaitkill)rHr�rrr/r/r0�on_hard_timeout�s
zTimeoutHandler.on_hard_timeoutcCs�td|j�zBt�|j�|jkrDtd|j�t�t�|j�tj�n|��Wnt	y`Yn0|j
jdd�rtdStd|j�zFt�|j�|jkr�td|j�t�t�|j�tj�nt
|jt�Wnt	y�Yn0dS)Nztimeout: sending TERM to %szIworker %s is a group leader. It is safe to kill (SIGTERM) the whole groupr*r�z/timeout: TERM timed-out, now sending KILL to %szIworker %s is a group leader. It is safe to kill (SIGKILL) the whole group)r�_namer��getpgidr��killpgr��SIGTERMr�r�_popen�wait�SIGKILLr��rH�workerr/r/r0r�s$zTimeoutHandler._trywaitkillc#s�|j|j}}t�}|j}|j}dd�}|jtkr�t�|j��|rXt�fdd�|D��}��	�D]j\}}|j
}	|j}
|
dur�|}
|j}|dur�|}||	|�r�||�q`||vr`||	|
�r`||�|�
|�q`dVq(dS)NcSs"|r|sdSt�||krdSdSr�r)r�rAr/r/r0�
_timed_out�sz2TimeoutHandler.handle_timeouts.<locals>._timed_outc3s|]}|�vr|VqdSr+r/)r�k�r�r/r0r
��z1TimeoutHandler.handle_timeouts.<locals>.<genexpr>)rr�setrrr�r��copyr��items�_time_accepted�
_soft_timeoutr�add)rHrrZdirtyrrr'r�r�Zack_time�soft_timeoutZhard_timeoutr/r)r0�handle_timeouts�s.


zTimeoutHandler.handle_timeoutscCsL|jtkr@z|��D]}t�d�qWqty<Yq@Yq0qtd�dS)Nr�ztimeout handler exiting)r�r�r2r�r�rr�rHr�r/r/r0r��s
zTimeoutHandler.bodycGs@|jdur|��|_zt|j�Wnty:d|_Yn0dSr+)r	r2r�
StopIteration�rHr5r/r/r0�handle_events

zTimeoutHandler.handle_event)r[r\r]rLrrrrr2r�r6rir/r/rdr0r�s&	rcsTeZdZd�fdd�	Zdd�Zdd�Zdd	d
�Zddd�Zd
d�Zddd�Z	�Z
S)�
ResultHandlerNcs^||_||_||_||_||_||_||_d|_d|_||_	|	|_
|
|_|��t
���dS)NF)r�r�r�r��join_exited_workers�putlockrr	�_shutdown_complete�check_timeouts�on_job_ready�on_ready_counters�
_make_methodsrcrL)rHr�r�r�r�r8r9rr;r<r=rdr/r0rLszResultHandler.__init__cCs|jdd�dS)NT)r2)�finish_at_shutdownrGr/r/r0r�sz!ResultHandler.on_stop_not_startedcsl�j��j��j��j���fdd�}����fdd�}dd�}t|t|t|i��_�fdd�}|�_dS)	Nc	s:d�_z�|�||||�Wnttfy4Yn0dSro)�R�_ackrr,)r�r��
time_acceptedr�r�)r�rr/r0�on_ack(s
z+ResultHandler._make_methods.<locals>.on_ackcs��dur�||||�z�|}Wnty6YdS0�jr�tt|���d�}|r�|�jvr��j|}|���|jd7_Wd�n1s�0Y|��s��dur����z|�	||�Wnty�Yn0dSrD)
rr=rr��worker_pidsZget_lockrNr�rVr�)r�r�r�r��itemZ
worker_pidr})r�r<r9rHr/r0�on_ready0s&

,z-ResultHandler._make_methods.<locals>.on_readyc
SsJzt�|t�Wn4tyD}zt|�tjkr0�WYd}~n
d}~00dSr+)r�r$rrr
r�r)r�r�rbr/r/r0�on_deathGs
z-ResultHandler._make_methods.<locals>.on_deathcs<|\}}z�||�Wnty6td||�Yn0dS)NzUnknown job state: %s (args=%s))rr)r�stater5)�state_handlersr/r0�on_state_changeRs
z4ResultHandler._make_methods.<locals>.on_state_change)	r�r9rr<r�r�r�rIrJ)rHrCrFrGrJr/)r�r<r9rrHrIr0r>"s�
zResultHandler._make_methodsr�c
cs�|j}|j}z||�\}}Wn8ttfyT}ztd|�t��WYd}~n
d}~00|jrx|jtksjJ�td�t��|r�|dur�td�t��||�|dkr�q�nq�dVqdS)N� result handler got %r -- exitingz,result handler found thread._state=TERMINATEzresult handler got sentinelr)r�rJr�r�rrr�r�)rHrAr�rJr�rrbr/r/r0�_process_resultZs(
zResultHandler._process_resultc	CsP|jtkrL|jdur |�d�|_zt|j�WnttfyJd|_Yn0dSro)r�r�r	rLrr4r)rHr-�eventsr/r/r0r6us

zResultHandler.handle_eventcCs\td�zD|jtkrBz|�d�D]}q Wq
ty>YqBYq
0q
W|��n
|��0dS)Nzresult handler startingr�)rr�r�rLrr?r3r/r/r0r�~s
zResultHandler.bodyFc
Cs�d|_|j}|j}|j}|j}|j}|j}|j}d}	|�r&|jt	k�r&|durT|�z|d�\}
}Wn4t
tfy�}ztd|�WYd}~dSd}~00|
r�|dur�td�q4||�z|dd�Wq4t
�y"t�}
|	s�|
}	n8|
|	dk�rtd�Y�q&tdtt|
|	dd	���Yq40q4t|d
��r�td�z,td�D]}|j���sZ�qd|��qDWnt
tf�y~Yn0td
t|�|j�dS)NTr�rKz&result handler ignoring extra sentinel)�shutdowng@z!result handler exiting: timed outz6result handler: all workers terminated, timeout in %ssrr�z"ensuring that outqueue is not fullr�z7result handler exiting: len(cache)=%s, thread._state=%s)r:r�r�r�r�r8r;rJr�r�r�r�rrjr�abs�minr�r�r��len)rHr2r�r�r�r�r8r;rJZtime_terminater�rrbr�r�r/r/r0r?�s\
�
�z ResultHandler.finish_at_shutdown)N)r�)NN)F)r[r\r]rLr�r>rLr6r�r?rir/r/rdr0r7
s�8

	r7c@s<eZdZdZdZeZeZeZeZe	Z	e
Z
dwdd�Zd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zdxd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Z d3d4�Z!dyd5d6�Z"dzd7d8�Z#d9d:�Z$d;d<�Z%d=d>�Z&d?d@�Z'dAdB�Z(dCdD�Z)dEdF�Z*dGdH�Z+dIdJ�Z,difdKdL�Z-d{dMdN�Z.d|dOdP�Z/d}dQdR�Z0d~dSdT�Z1ddUdV�Z2diddddddddddfdWdX�Z3dYdZ�Z4d�d[d\�Z5d�d]d^�Z6d�d_d`�Z7e8dadb��Z9dcdd�Z:dedf�Z;dgdh�Z<e8didj��Z=dkdl�Z>dmdn�Z?e8dodp��Z@eAdqdr��ZBeAdsdt��ZCeDdudv��ZEdS)��PoolzS
    Class which supports an async version of applying functions to arguments.
    TNr/rFcKs�|pt�|_||_|��t�|_i|_t|_||_	||_
||_||_||_
||_||_|p^t|_|
|_||_||_|
|_||_i|_||_t|p�|j	dup�|j
du�|_|r�tdur�t�td��d}|dur�|��n||_ |p�t!|j d�|_"t#||	p�d�|_#|du�rt$|��st%d��|du�r:t$|��s:t%d��|jj&|_'g|_(i|_)i|_*||_+|�pjt,|j �|_-t.|j �D]}|�/|��qx|�0|�|_1|�r�|j1�2�|�3|j|j4|j5|j(|j�|_6|�r�|j6�2�d|_7|j�r$|�8|j(|j|j
|j	�|_9t:�|_;d|_<|�=�|�s6|j9j>|_7nd|_9d|_<d|_;|�?�|_@|j@j>|_A|�rZ|j@�2�tB||jC|j|jD|j5|j(|j1|j6|j@|j|j9|�E�f
dd�|_FdS)	N�WSoft timeouts are not supported: on this platform: It does not have the SIGUSR1 signal.�drzinitializer must be a callablez on_process_exit must be callableF�)r5Zexitpriority)Gr�_ctx�synack�
_setup_queuesr�
_taskqueue�_cacher�r�rAr1�_maxtasksperchild�_max_memory_per_child�_initializer�	_initargs�_on_process_exit�LOST_WORKER_TIMEOUT�lost_worker_timeout�
on_process_up�on_process_down�on_timeout_set�on_timeout_cancel�threadsZreaders�
allow_restart�bool�enable_timeoutsr��warnings�warn�UserWarningrr��round�max_restartsr�callable�	TypeError�Process�_Process�_pool�	_poolctrl�_on_ready_counters�putlocksrC�_putlockr��_create_worker_processr��_worker_handlerr�r�r��	_outqueue�
_task_handlerr;r�_timeout_handler�Lock�_timeout_handler_mutex�_timeout_handler_started�_start_timeout_handlerr6�create_result_handler�_result_handler�handle_result_eventr�_terminate_pool�_inqueue�_help_stuff_finish_args�
_terminate)rHrrrrsZmaxtasksperchildrAr1rarnZmax_restart_freqrbrcrdrerfZ	semaphorervrgrWZon_process_exit�contextrurir<r�r/r/r0rL�s�
���

�
�


��z
Pool.__init__cOs|j|i|��Sr+)rr)rHr5�kwdsr/r/r0rqIszPool.ProcesscCs|�|j|d��S)N)�target)r~rqr%r/r/r0�
WorkerProcessLszPool.WorkerProcessc
Ks:|j|j|j|j|j|j|j|j|j|j	f	d|j
i|��S)Nr=)r7rzr�rZ�_poll_result�_join_exited_workersrwrr;r<ru)rH�extra_kwargsr/r/r0r�Os���zPool.create_result_handlercCsdSr+r/)rHr�r�r�r�r/r/r0r<XszPool.on_job_readycCs|j|j|jfSr+)r�r{rsrGr/r/r0r�[szPool._help_stuff_finish_argscCs"zt�WStyYdS0dSrD)r�NotImplementedErrorrGr/r/r0r^szPool.cpu_countcGs|jj|�Sr+)r�r6r5r/r/r0r�dszPool.handle_result_eventcCsdSr+r/)rHr&�queuesr/r/r0�_process_register_queuesgszPool._process_register_queuescst�fdd�t|j�D�d�S)Nc3s$|]\}}|j�kr||fVqdSr+r�r
r�r/r0r
ks
�z'Pool._process_by_pid.<locals>.<genexpr>r)rr�rsr�r/r�r0rjs
��zPool._process_by_pidcCs|j|jdfSr+)r�rzrGr/r/r0�get_process_queuespszPool.get_process_queuescCs�|jr|j��nd}|��\}}}|j�d�}|�|j||||j|j|j	||j
|j|j|j
|d��}|j�|�|�||||f�|j�dd�|_d|_||_|��||j|j<||j|j<|jr�|�|�|S)Nr�)rxr|rur}rqZ
PoolWorkerT)rgrV�Eventr��Valuer�rnr]r^r[r_rf�_wrap_exceptionr\rs�appendr��name�replacer��indexr�rtr�rurb)rHr�rryrzr{r}�wr/r/r0rxss,
�

zPool._create_worker_processcCsdSr+r/r%r/r/r0�process_flush_queues�szPool.process_flush_queuescs|d}dd�t|j���D�D]2}|p(t�}|j\}}|||jkr|�||�q|rdt|j�sdt	��ii�}t
tt|j���D]�}|j|}|j}	|j
}
|
dus�|	dur�td|�|
dur�|��td|�|�|j<|	||j<|	ttfv�rt|dd��std|j|jt|	�d	d
�|�|�|j|=|j|j=|j|j=q���rxdd�|jD��t|j���D]�}t��fdd
�|��D�d�}|�r�|�||�|���s6|�|��p�d	}	��|�}|�r�t|dd��r�|�|	�n|� |||	�nJ|j!}
|j"}|
�r|
�#��s|�||
j�n|�rd|�#��sd|�||j��qd���D](}|j$�rB|�s^|�%|�|�$|��qBt|���SgS)z�Cleanup after any worker processes which have exited due to
        reaching their specified lifetime. Returns True if any workers were
        cleaned up.
        NcSsg|]}|��s|jr|�qSr/)r��_worker_lost)rr�r/r/r0�
<listcomp>�s�z-Pool._join_exited_workers.<locals>.<listcomp>z!Supervisor: cleaning up worker %dzSupervisor: worked %d joined�_controlled_terminationFz Process %r pid:%r exited with %rrr�cSsg|]
}|j�qSr/r��rr�r/r/r0r��r*c3s"|]}|�vs|�vr|VqdSr+r/�rr��Zall_pids�cleanedr/r0r
�s�z,Pool._join_exited_workers.<locals>.<genexpr>�_job_terminated)&r2rZ�valuesrr��_lost_worker_timeout�mark_as_worker_lostrQrsrj�reversedr�r�r"rr�r�r)r��getattrr:r�r	r�rtrurrD�on_job_process_downr�r��_set_terminated�on_job_process_lost�	_write_to�_scheduled_for�	_is_aliverc�_process_cleanup_queues)rHrNr�r�Z	lost_timeZlost_ret�	exitcodesr�r&r��popenZ
acked_by_gonerZwrite_toZ	sched_forr/r�r0r��s|








��

�

�
zPool._join_exited_workerscCsdSr+r/)rHr�r&r/r/r0�on_partial_read�szPool.on_partial_readcCsdSr+r/r%r/r/r0r��szPool._process_cleanup_queuescCsdSr+r/)rHr�Zpid_goner/r/r0r��szPool.on_job_process_downcCst�|f|_dSr+)rr�)rHr�r�r�r/r/r0r��szPool.on_job_process_lostcCsDztd�t|�|j���Wn$ty>|�ddt�f�Yn0dS)Nz(Worker exited prematurely: {0} Job: {1}.F)rr�r	rr�r)rHr�r�r/r/r0r��s
��zPool.mark_as_worker_lostcCs|Sr+r/rGr/r/r0�	__enter__�szPool.__enter__cGs|��Sr+)r�)rHr�r/r/r0�__exit__�sz
Pool.__exit__cCsdSr+r/�rH�nr/r/r0�on_growszPool.on_growcCsdSr+r/r�r/r/r0�	on_shrinkszPool.on_shrinkcCsbt|���D]H\}}|jd8_|jr2|j��|��|�d�||dkrq^qtd��dS)Nrz&Can't shrink pool. All processes busy!)r��
_iterinactiver�rwrIZterminate_controlledr��
ValueError)rHr�r�r&r/r/r0rIs

zPool.shrinkcCs:t|�D]"}|jd7_|jr|j��q|�|�dSrD)r�r�rwrSr�)rHr�r�r/r/r0rSs
z	Pool.growccs |jD]}|�|�s|VqdSr+)rs�_worker_activer%r/r/r0r�s

zPool._iterinactivecCs(|j��D]}|j|��vr
dSq
dS)NTF)rZr�r�rD)rHr&r�r/r/r0r�szPool._worker_activec	Cs�t|jt|j��D]j}|jtkr(dSz"|rH||ttfvrH|j�	�Wnt
yf|j�	�Yn0|�|���t
d�qdS)z�Bring the number of pool processes up to the specified number,
        for use after reaping workers which have exited.
        Nzadded worker)r�r�rQrsr�r�r)r�r�step�
IndexErrorrx�_avail_indexr)rHr�r�r/r/r0�_repopulate_pool$s
zPool._repopulate_poolcsDt|j�|jksJ�tdd�|jD���t�fdd�t|j�D��S)Ncss|]}|jVqdSr+)r�)rrr/r/r0r
5r*z$Pool._avail_index.<locals>.<genexpr>c3s|]}|�vr|VqdSr+r/)rr���indicesr/r0r
6r*)rQrsr�r+rr�rGr/r�r0r�3szPool._avail_indexcCs
|��Sr+)r�rGr/r/r0�did_start_ok8szPool.did_start_okcCs<|��}|�|�tt|��D]}|jdur|j��qdS)zF"Clean up any exited workers and start replacements for them.
        N)r�r�r�rQrwrV)rHZjoinedr�r/r/r0r�;s


zPool._maintain_poolc
Cs�|jjtkr�|jtkr�z|��Wn\tyF|��|���Yn:ty~}z"t|�t	j
krht|��WYd}~n
d}~00dSr+)ryr�r�r�rr�r�rr
r��ENOMEM�MemoryErrorr�r/r/r0�
maintain_poolDszPool.maintain_poolcsF�j���_�j���_�jjj�_�jjj�_	�fdd�}|�_
dS)Ncs�jj�|�rd���fSdSr�)rzr�r�r�r�rGr/r0r�Wsz(Pool._setup_queues.<locals>._poll_result)rV�SimpleQueuer�rzr�r�r�r�r�r�r��rHr�r/rGr0rXQszPool._setup_queuescCsP|jrL|jdurL|j�&|js.d|_|j��Wd�n1sB0YdSr�)rfr|r~rr�rGr/r/r0r�]s
zPool._start_timeout_handlercCs |jtkr|�|||���SdS)z8
        Equivalent of `func(*args, **kwargs)`.
        N)r�r��apply_asyncr�)rH�funcr5r�r/r/r0�applyfs
z
Pool.applycCs"|jtkr|�||t|���SdS)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).
        N)r�r��
_map_asyncr9r��rHr��iterable�	chunksizer/r/r0r8ms
�zPool.starmapcCs"|jtkr|�||t|||�SdS)z=
        Asynchronous version of `starmap()` method.
        N)r�r�r�r9�rHr�r�r��callback�error_callbackr/r/r0�
starmap_asyncws
�zPool.starmap_asynccCs |jtkr|�|||���SdS)zx
        Apply `func` to each element in `iterable`, collecting the results
        in a list that is returned.
        N)r�r��	map_asyncr�r�r/r/r0r3�s
zPool.mapcs�|jtkrdS|p|j}|dkrXt|j|d��|j���fdd�t|�D��jf��S|dksdJ�t	�
�||�}t|j|d��|j��fdd�t|�D��jf�dd��D�SdS)zP
        Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
        Nr�rac3s(|] \}}t�j|�|fiffVqdSr+�r�r�rr��x�r�r�r/r0r
�s�zPool.imap.<locals>.<genexpr>c3s(|] \}}t�j|t|fiffVqdSr+�r�rr6r��r�r/r0r
�s�css|]}|D]
}|Vq
qdSr+r/�r�chunkrEr/r/r0r
�r*)r�r�ra�IMapIteratorrZrYr�r��_set_lengthrR�
_get_tasks�rHr�r�r�ra�task_batchesr/r�r0�imap�s4

����
��z	Pool.imapcs�|jtkrdS|p|j}|dkrXt|j|d��|j���fdd�t|�D��jf��S|dksdJ�t	�
�||�}t|j|d��|j��fdd�t|�D��jf�dd��D�SdS)zL
        Like `imap()` method but ordering of results is arbitrary.
        Nrr�c3s(|] \}}t�j|�|fiffVqdSr+r�r�r�r/r0r
�s�z&Pool.imap_unordered.<locals>.<genexpr>c3s(|] \}}t�j|t|fiffVqdSr+r�r�r�r/r0r
�s�css|]}|D]
}|Vq
qdSr+r/r�r/r/r0r
�r*)r�r�ra�IMapUnorderedIteratorrZrYr�r�r�rRr�r�r/r�r0�imap_unordered�s4

����
��zPool.imap_unorderedcCs|jtkrdS|	p|j}	|
p |j}
|p*|j}|	rJtdurJt�td��d}	|jtk�r|durd|j	n|}|r�|j
dur�|j
��t|j
|||||	|
||j|j||jr�|jnd|
d�
}|
s�|	r�|��|jr�|j�t|jd|||ffgdf�n|�t|jd|||ff�|SdS)a
        Asynchronous equivalent of `apply()` method.

        Callback is called when the functions return value is ready.
        The accept callback is called when the job is accepted to be executed.

        Simplified the flow is like this:

            >>> def apply_async(func, args, kwds, callback, accept_callback):
            ...     if accept_callback:
            ...         accept_callback()
            ...     retval = func(*args, **kwds)
            ...     if callback:
            ...         callback(retval)

        NrS)rdre�callbacks_propagate�send_ack�correlation_id)r�r�r1rArar�rjrkrlrvrwrF�ApplyResultrZrdrerWr�r�rfrYr�r�rr�)rHr�r5r�r�r��accept_callback�timeout_callbackZwaitforslotr1rArar�r�r�r/r/r0r��sB



�

�	��zPool.apply_asynccCsdSr+r/)rH�responser�r��fdr/r/r0r��sz
Pool.send_ackc
Csn|�|�\}}|durjzt||p"t�Wn4ty\}zt|�tjkrH�WYd}~nd}~00d|_d|_dSr�)	rr�rrr
r�rr�r�)rHr��sigrr�rbr/r/r0�
terminate_job�szPool.terminate_jobcCs|�||t|||�S)z<
        Asynchronous equivalent of `map()` method.
        )r�r6r�r/r/r0r�
s�zPool.map_asyncc	s�|jtkrdSt|d�s t|�}|durPtt|�t|j�d�\}}|rP|d7}t|�dkr`d}t�|||�}t	|j
|t|�||d��|j���fdd�t
|�D�df��S)	zY
        Helper function to implement map, starmap and their async counterparts.
        N�__len__r&rr�r�c3s(|] \}}t�j|�|fiffVqdSr+r�r���mapperr�r/r0r
's�z"Pool._map_async.<locals>.<genexpr>)r�r�r�r2�divmodrQrsrRr��	MapResultrZrYr�r�)	rHr�r�r�r�r�r��extrar�r/r�r0r�s(

���zPool._map_asyncccs0t|�}tt�||��}|s dS||fVqdSr+)r��tupler7�islice)r��it�sizer�r/r/r0r�+s
zPool._get_taskscCstd��dS)Nz:pool objects cannot be passed between processes or pickled)r�rGr/r/r0r�4s�zPool.__reduce__cCsLtd�|jtkrHt|_|jr(|j��|j��|j�	d�t
|j�dS)Nzclosing pool)rr�r�r�rwrWryr�rYr�rBrGr/r/r0r�9s


z
Pool.closecCs$td�t|_|j��|��dS)Nzterminating pool)rr�r�ryr�r�rGr/r/r0r�Cs
zPool.terminatecCst|�dSr+)rB)�task_handlerr/r/r0�_stop_task_handlerIszPool._stop_task_handlercCs�|jttfvsJ�td�t|j�td�|�|j�td�t|j�td�t	|j
�D]2\}}td|dt|j
�|�|jdur\|�
�q\td�dS)Nzjoining worker handler�joining task handler�joining result handlerzresult handler joinedzjoining worker %s/%s (%r)rzpool join complete)r�r�r�rrBryr�r{r�r�rsrQr"r�)rHr�rr/r/r0r�Ms



z	Pool.joincCs|j��D]}|��q
dSr+)rtr�r+)rH�er/r/r0�restart\szPool.restartcCs>td�|j��|��r:|j��r:|j��t�d�qdS)Nz7removing tasks from inqueue until task handler finishedr)	rZ_rlockrF�is_aliver�r�r�r�r�)�inqueuer�rsr/r/r0�_help_stuff_finish`s


zPool._help_stuff_finishcCs|�d�dSr+)r�)�clsr�r�r/r/r0�_set_result_sentineliszPool._set_result_sentinelcCs>td�|��|��|�d�td�|j|
�|��|�||�|	durX|	��|r�t|dd�r�td�|D]}|��rv|��qvtd�|�|�td�|��|	dur�td�|	�t	�|�rt|dd��rtd	�|D]*}|�
�r�td
|j�|jdur�|�
�q�td�|�r,|��|�r:|��dS)Nzfinalizing poolz&helping task handler/workers to finishrr�zterminating workersr�r�zjoining timeout handlerzjoining pool workerszcleaning up worker %dzpool workers joined)rr�r�rrr�r�r�r?�TIMEOUT_MAXrr�r"r�r�)rr�rr�r�Zworker_handlerr�Zresult_handlerr�Ztimeout_handlerZhelp_stuff_finish_argsrr/r/r0r�msD






zPool._terminate_poolcCsdd�|jD�S)NcSsg|]}|jj�qSr/)r"rr�r/r/r0r��r*z*Pool.process_sentinels.<locals>.<listcomp>)rsrGr/r/r0�process_sentinels�szPool.process_sentinels)NNr/NNNNNrNNNNTNFFFNNNF)F)r)r)N)NNN)N)rN)rN)N)NNN)NNN)Fr[r\r]r^r�rnr�r�rr7rrLrqr�r�r<r�rr�r�rr�rxr�r�r�r�r�r�r�r�r�r�r�rIrSr�r�r�r�r�r�r�rXr�r�r8r�r3r�r�r�r�r�r�r��staticmethodr�r�r�r�r�r�r�r�classmethodrr��propertyrr/r/r/r0rR�s��
z	
S

	
	

�
	

�
�
8
�
	�






6rRc@s�eZdZdZdZdZdddddedddddfdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zd$dd�Zdd�Zd%dd�Zd&dd�Zdd�Zd'dd�Zd d!�Zd"d#�ZdS)(r�Nr/cCs�|
|_t�|_t��|_tt�|_||_	||_
||_||_||_
||_||_||_|	|_|
|_|pdd|_||_d|_d|_d|_d|_d|_|||j<dS)Nr/F)r�r}�_mutexr=r��_eventr�job_counterrrZ�	_callback�_accept_callback�_error_callback�_timeout_callbackrr/r��_on_timeout_set�_on_timeout_cancel�_callbacks_propagate�	_send_ack�	_accepted�
_cancelledrr.�_terminated)rHr�r�r�r�r�r1rArardrer�r�r�r/r/r0rL�s,


zApplyResult.__init__cCsdj|jj|j|j|��d�S)Nz&<{name}: {id} ack:{ack} ready:{ready}>)r��idZackr�)r�rer[rrr�rGr/r/r0rg�s�zApplyResult.__repr__cCs
|j��Sr+)rr�rGr/r/r0r��szApplyResult.readycCs|jSr+)rrGr/r/r0�accepted�szApplyResult.acceptedcCs|��sJ�|jSr+)r��_successrGr/r/r0�
successful�szApplyResult.successfulcCs
d|_dS)zOnly works if synack is used.TN)rrGr/r/r0�_cancel�szApplyResult._cancelcCs|j�|jd�dSr+)rZ�poprrGr/r/r0�discard�szApplyResult.discardcCs
||_dSr+)r�rHrkr/r/r0r��szApplyResult.terminatecCs<zt|p
d��Wn$ty6|�ddt�f�Yn0dS�NrF)rr�rrr/r/r0r��szApplyResult._set_terminatedcCs|jr|jgSgSr+�rrGr/r/r0rD�szApplyResult.worker_pidscCs|j�|�dSr+)rr#r�r/r/r0r#�szApplyResult.waitcCs.|�|�|��st�|jr"|jS|jj�dSr+)r#r�rrrQ�	exceptionr�r/r/r0r��s
zApplyResult.getc
Osb|r^z||i|��WnF|jy,�Yn2ty\}ztd|dd�WYd}~n
d}~00dS)Nz"Pool callback raised exception: %rrr�)rr�r:)rHr�r5r<rbr/r/r0�safe_apply_callback�s�zApplyResult.safe_apply_callbackFcCs,|jdur(|j|j||r|jn|jd�dS)N)rrA)rr#r/r)rHrr/r/r0r	s

�zApplyResult.handle_timeoutcCs�|j��|jr|�|�|\|_|_|j��|jrD|j�|j	d�|j
r`|jr`|�|j
|j�|jdur�|jr�|js�|�|j|j�Wd�n1s�0YdSr+)
r
rrrQrr+rrZrrr
r#r�rHr�r�r/r/r0r�s&

�
���zApplyResult._setc
Cs�|j��t|jrP|jrPd|_|r@|�t||j|�Wd�SWd�dSd|_||_||_|��rz|j	�
|jd�|jr�|�||j|j
�t}|j�rNzrz|�||�Wn.|jy�t}�Ynty�t}Yn0W|j�rN|�rN|�|||j|�Wd�Sn<|j�rL|�rL|�|||j|�YWd�S0|j�rn|�rn|�|||j|�Wd�n1�s�0YdSr�)r
rrrr�rr.rr�rZrrr/rr�rZ_propagate_errorsr�)rHr�rBr�r�r�r/r/r0rA%s@
 
��
� zApplyResult._ack)N)N)N)F)r[r\r]r�r�r�r`rLrgr�rrrrr�r�rDr#r�r#rr�rAr/r/r/r0r��s2�



	

r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)r�cCs�tj||||d�d|_||_dg||_dg||_dg||_dg||_||_|dkrvd|_	|j
��||j=n||t
||�|_	dS)Nr�TFr)r�rLr�_lengthrQrrr.�
_chunksize�_number_leftrr+rrh)rHr�r��lengthr�r�r/r/r0rLMs�

zMapResult.__init__cCs�|\}}|rv||j||j|d|j�<|jd8_|jdkr�|jrT|�|j�|jrj|j�|jd�|j�	�n>d|_
||_|jr�|�|j�|jr�|j�|jd�|j�	�dS)NrrF)rQr&r'r
rrZrrrr+rr)rHr�Zsuccess_result�successr�r/r/r0r�_s"
zMapResult._setcGsj||j}t|d|j|j�}t||�D]"}d|j|<||j|<||j|<q*|��rf|j�	|j
d�dS�NrT)r&rPr%r�rrr.r�rZrr)rHr�rBr�r5r�r?�jr/r/r0rAss


zMapResult._ackcCs
t|j�Sr+)�allrrGr/r/r0r}szMapResult.acceptedcCsdd�|jD�S)NcSsg|]}|r|�qSr/r/r�r/r/r0r��r*z)MapResult.worker_pids.<locals>.<listcomp>r!rGr/r/r0rD�szMapResult.worker_pidsN)r[r\r]rLr�rArrDr/r/r/r0r�Ks

r�c@sZeZdZdZefdd�Zdd�Zddd�ZeZdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dS)r�NcCsZt�t���|_tt�|_||_t�|_	d|_
d|_d|_i|_
g|_||_|||j<dSr )r=�	Conditionr}rPrrrrZr�_itemsrr%�_ready�	_unsorted�_worker_pidsr�)rHr�rar/r/r0rL�s
zIMapIterator.__init__cCs|Sr+r/rGr/r/r0�__iter__�szIMapIterator.__iter__cCs�|j��z|j��}Wnpty�|j|jkr:d|_t�|j�|�z|j��}Wn,ty�|j|jkrxd|_t�t	�Yn0Yn0Wd�n1s�0Y|\}}|r�|St
|��dSr�)rPr.�popleftr�rr%r/r4r#rr�)rHrArEr)rNr/r/r0r�s&.zIMapIterator.nextcCs�|j��|j|krn|j�|�|jd7_|j|jvrb|j�|j�}|j�|�|jd7_q,|j��n
||j|<|j|jkr�d|_|j	|j
=Wd�n1s�0YdSr*)rPrr.r�r0rrRr%r/rZrr$r/r/r0r��s

zIMapIterator._setcCsV|j�<||_|j|jkr4d|_|j��|j|j=Wd�n1sH0YdSr�)rPr%rr/rRrZr)rHr(r/r/r0r��s
zIMapIterator._set_lengthcGs|j�|�dSr+)r1r�)rHr�rBr�r5r/r/r0rA�szIMapIterator._ackcCs|jSr+)r/rGr/r/r0r��szIMapIterator.readycCs|jSr+)r1rGr/r/r0rD�szIMapIterator.worker_pids)N)r[r\r]r�r`rLr2r�__next__r�r�rAr�rDr/r/r/r0r��s

r�c@seZdZdd�ZdS)r�cCsj|j�P|j�|�|jd7_|j��|j|jkrHd|_|j|j=Wd�n1s\0YdSr*)	rPr.r�rrRr%r/rZrr$r/r/r0r��s
zIMapUnorderedIterator._setN)r[r\r]r�r/r/r/r0r��sr�c@s:eZdZddlmZeZddd�Zdd�Zed	d
��Z	dS)�
ThreadPoolr)rqNr/cCst�||||�dSr+)rRrL)rHrrrrsr/r/r0rL�szThreadPool.__init__cs:t��_t��_�jj�_�jj�_�fdd�}|�_dS)Ncs,zd�j|d�fWSty&YdS0dSr�)r�rr�rGr/r0r��sz.ThreadPool._setup_queues.<locals>._poll_result)rr�rzr�r�r�r�r�r�r/rGr0rX�s

zThreadPool._setup_queuescCsT|j�:|j��|j�dgt|��|j��Wd�n1sF0YdSr+)�	not_empty�queuerW�extendrQrT)rr�r�r/r/r0r�s
zThreadPool._help_stuff_finish)NNr/)
r[r\r]�dummyrqrrLrXrrr/r/r/r0r5�s

r5)N)er,r�r7r�r�r�r�r=r�rj�collectionsr�	functoolsr�rrr�commonrr	r
rr�compatr
rrr�rr9r�
exceptionsrrrrrrrrr7rrrrr r��version_infor_�systemZ_winr#r�r$r$rr,�	SemaphorerKr�r�r�r�r�r�r�r�r)r�r�r�r�r`r�r��countrr}r1r6r9r:rBrCr�r`rjrmrnr�r�r�rr7rRr�r�r�r�r5r/r/r/r0�<module>
s�$	



;)%K:o=R