�`^c@sTdgZddlZddlZddlZddlZddlZddlmZmZm Z ddl
mZmZdZ
dZdZej�Zd�Zd efd
��YZefed�Zdefd��YZd
efd��YZeZdefd��YZdefd��YZdefd��YZdefd��YZdS(tPooli�N(tProcesst cpu_counttTimeoutError(tFinalizetdebugiiicCs
t|�S(N(tmap(targs((s*/sys/lib/python2.7/multiprocessing/pool.pytmapstar@stMaybeEncodingErrorcBs)eZdZd�Zd�Zd�ZRS(sVWraps possible unpickleable errors, so they can be
safely sent through the socket.cCsAt|�|_t|�|_tt|�j|j|j�dS(N(treprtexctvaluetsuperR t__init__(tselfRR((s*/sys/lib/python2.7/multiprocessing/pool.pyRKscCsd|j|jfS(Ns(Error sending result: '%s'. Reason: '%s'(RR(R((s*/sys/lib/python2.7/multiprocessing/pool.pyt__str__Ps cCsdt|�S(Ns<MaybeEncodingError: %s>(tstr(R((s*/sys/lib/python2.7/multiprocessing/pool.pyt__repr__Ts(t__name__t
__module__t__doc__RRR(((s*/sys/lib/python2.7/multiprocessing/pool.pyR Gs cCs�|dks0t|�tkr*|dks0t�|j}|j}t|d�rn|jj�|j j�n|dk r�||�nd}x/|dks�|r�||kr�y
|�}Wn"t
tfk
r�td�PnX|dkr�d�Pn|\} }
}}}
yt
|||
�f}Wntk
rI}t|f}nXy|| |
|f�WnMtk
r�}t||d�}td|�|| |
t|ff�nX|d7}q�Wtd|�dS(Nit_writers)worker got EOFError or IOError -- exitingsworker got sentinel -- exitingis0Possible encoding error while sending result: %ssworker exiting after %d tasks(tNonettypetinttAssertionErrortputtgetthasattrRtcloset_readertEOFErrortIOErrorRtTruet ExceptiontFalseR (tinqueuetoutqueuetinitializertinitargstmaxtasksRRt completedttasktjobtitfuncRtkwdstresulttetwrapped((s*/sys/lib/python2.7/multiprocessing/pool.pytworkerXs@0
!
cBseZdZeZddddd�Zd�Zd�Zd�Zd�Z did�Z
dd�Zdd �Zdd
�Z
didd�Zddd�Zed
��Zed��Zed��Zed��Zd�Zd�Zd�Zd�Zed��Zed��ZRS(sH
Class which supports an async version of the `apply()` builtin
cCs/|j�tj�|_i|_t|_||_||_||_|dkr|y
t
�}Wq|tk
rxd}q|Xn|dkr�td��n|dk r�t
|d�r�td��n||_g|_|j�tjdtjd|f�|_t|j_t|j_|jj�tjdtjd|j|j|j|j|jf�|_t|j_t|j_|jj�tjdtjd|j|j|jf�|_ t|j _t|j _|j j�t!||j"d|j|j#|j|j|j|j|j |jfdd�|_$dS( Nis&Number of processes must be at least 1t__call__sinitializer must be a callablettargetRtexitpriorityi(%t
_setup_queuestQueuet
_taskqueuet_cachetRUNt_statet_maxtasksperchildt_initializert _initargsRRtNotImplementedErrort
ValueErrorRt TypeErrort
_processest_poolt_repopulate_poolt threadingtThreadRt_handle_workerst_worker_handlerR"tdaemontstartt
_handle_taskst
_quick_putt _outqueuet
_task_handlert_handle_resultst
_quick_gett_result_handlerRt_terminate_poolt_inqueuet
_terminate(Rt processesR'R(tmaxtasksperchild((s*/sys/lib/python2.7/multiprocessing/pool.pyR�sX
cCswt}xjttt|j���D]M}|j|}|jdk r"td|�|j�t }|j|=q"q"W|S(s�Cleanup after any worker processes which have exited due to reaching
their specified lifetime. Returns True if any workers were cleaned up.
scleaning up worker %dN(
R$treversedtrangetlenRDtexitcodeRRtjoinR"(RtcleanedR-R3((s*/sys/lib/python2.7/multiprocessing/pool.pyt_join_exited_workers�s"
c
Cs�x�t|jt|j��D]�}|jdtd|j|j|j|j |j
f�}|jj|�|jj
dd�|_t|_|j�td�qWdS(s�Bring the number of pool processes up to the specified number,
for use after reaping workers which have exited.
R5RRt
PoolWorkersadded workerN(RYRCRZRDRR3RTRNR>R?R=tappendtnametreplaceR"RJRKR(RR-tw((s*/sys/lib/python2.7/multiprocessing/pool.pyRE�s#
cCs|j�r|j�ndS(sEClean up any exited workers and start replacements for them.
N(R^RE(R((s*/sys/lib/python2.7/multiprocessing/pool.pyt_maintain_pool�scCsPddlm}|�|_|�|_|jjj|_|jjj|_ dS(Ni(tSimpleQueue(
tqueuesReRTRNRtsendRMRtrecvRQ(RRe((s*/sys/lib/python2.7/multiprocessing/pool.pyR7�s
cCs.|jtkst�|j|||�j�S(s1
Equivalent of `apply()` builtin
(R<R;Rtapply_asyncR(RR.RR/((s*/sys/lib/python2.7/multiprocessing/pool.pytapply�scCs.|jtkst�|j|||�j�S(s/
Equivalent of `map()` builtin
(R<R;Rt map_asyncR(RR.titerablet chunksize((s*/sys/lib/python2.7/multiprocessing/pool.pyR�sics�|jtkst�|dkrft|j��|jj��fd�t|�D��jf��S|dksxt�t j
�||�}t|j��|jj�fd�t|�D��jf�d��D�SdS(sZ
Equivalent of `itertools.imap()` -- can be MUCH slower than `Pool.map()`
ic3s0|]&\}}�j|�|fifVqdS(N(t_job(t.0R-tx(R.R0(s*/sys/lib/python2.7/multiprocessing/pool.pys <genexpr>sc3s0|]&\}}�j|t|fifVqdS(N(RnR(RoR-Rp(R0(s*/sys/lib/python2.7/multiprocessing/pool.pys <genexpr>scss"|]}|D]}|Vq
qdS(N((Rotchunktitem((s*/sys/lib/python2.7/multiprocessing/pool.pys <genexpr>
sN(R<R;RtIMapIteratorR:R9Rt enumeratet_set_lengthRt
_get_tasks(RR.RlRmttask_batches((R.R0s*/sys/lib/python2.7/multiprocessing/pool.pytimap�scs�|jtkst�|dkrft|j��|jj��fd�t|�D��jf��S|dksxt�t j
�||�}t|j��|jj�fd�t|�D��jf�d��D�SdS(sK
Like `imap()` method but ordering of results is arbitrary
ic3s0|]&\}}�j|�|fifVqdS(N(Rn(RoR-Rp(R.R0(s*/sys/lib/python2.7/multiprocessing/pool.pys <genexpr>sc3s0|]&\}}�j|t|fifVqdS(N(RnR(RoR-Rp(R0(s*/sys/lib/python2.7/multiprocessing/pool.pys <genexpr>scss"|]}|D]}|Vq
qdS(N((RoRqRr((s*/sys/lib/python2.7/multiprocessing/pool.pys <genexpr>sN(R<R;RtIMapUnorderedIteratorR:R9RRtRuRRv(RR.RlRmRw((R.R0s*/sys/lib/python2.7/multiprocessing/pool.pytimap_unorderedscCsV|jtkst�t|j|�}|jj|jd|||fgdf�|S(s>
Asynchronous equivalent of `apply()` builtin
N( R<R;RtApplyResultR:R9RRnR(RR.RR/tcallbackR0((s*/sys/lib/python2.7/multiprocessing/pool.pyRi!s+cs�|jtkst�t|d�s3t|�}n|dkr}tt|�t|j�d�\}}|r}|d7}q}nt|�dkr�d}nt j
|||�}t|j|t|�|��|j
j�fd�t|�D�df��S(s<
Asynchronous equivalent of `map()` builtin
t__len__iiic3s0|]&\}}�j|t|fifVqdS(N(RnR(RoR-Rp(R0(s*/sys/lib/python2.7/multiprocessing/pool.pys <genexpr>;sN(R<R;RRtlistRtdivmodRZRDRRvt MapResultR:R9RRt(RR.RlRmR|textraRw((R0s*/sys/lib/python2.7/multiprocessing/pool.pyRk*s( cCsotj�}xB|jtks6|jrP|jtkrP|j�tjd�qW|j j
d�td�dS(Ng����sworker handler exiting(
RFtcurrent_threadR<R;R:t TERMINATERdttimetsleepR9RRR(tpooltthread((s*/sys/lib/python2.7/multiprocessing/pool.pyRH?s*
cCsjtj�}x�|jd�D]�\}}d}x�t|�D]�\}} |jratd�Pny|| �Wq>tk
r�}
| d \}}y||j |t
|
f�Wq�tk
r�q�Xq>Xq>W|rtd�||d�qqPqWtd�y@td�|jd�td�x|D]}
|d�q)WWnt
k
r[td �nXtd
�dS(Ni�s'task handler found thread._state != RUNisdoing set_length()istask handler got sentinels/task handler sending sentinel to result handlers(task handler sending sentinel to workerss/task handler got IOError when sending sentinelsstask handler exiting(RFR�titerRRRtR<RR#t_setR$tKeyErrorRR!(t taskqueueRR&R�tcacheR�ttaskseqt
set_lengthR-R+R1R,tindtp((s*/sys/lib/python2.7/multiprocessing/pool.pyRLLs<
cCs�tj�}x�y
|�}Wn"ttfk
r@td�dSX|jrm|jtks_t�td�Pn|dkr�td�Pn|\}}}y||j ||�Wqt
k
r�qXqx�|ri|jtkriy
|�}Wn"ttfk
rtd�dSX|dkr+td�q�n|\}}}y||j ||�Wq�t
k
req�Xq�Wt|d�r�td�y5x.td�D] }|j
j�s�Pn|�q�WWq�ttfk
r�q�Xntdt|�|j�dS( Ns.result handler got EOFError/IOError -- exitings,result handler found thread._state=TERMINATEsresult handler got sentinels&result handler ignoring extra sentinelRs"ensuring that outqueue is not fulli
s7result handler exiting: len(cache)=%s, thread._state=%s(RFR�R!R RR<R�RRR�R�RRYRtpollRZ(R&RR�R�R+R,R-tobj((s*/sys/lib/python2.7/multiprocessing/pool.pyRPvsX
ccsCt|�}x0ttj||��}|s1dS||fVqdS(N(R�ttuplet itertoolstislice(R.tittsizeRp((s*/sys/lib/python2.7/multiprocessing/pool.pyRv�scCstd��dS(Ns:pool objects cannot be passed between processes or pickled(R@(R((s*/sys/lib/python2.7/multiprocessing/pool.pyt
__reduce__�scCs5td�|jtkr1t|_t|j_ndS(Nsclosing pool(RR<R;tCLOSERI(R((s*/sys/lib/python2.7/multiprocessing/pool.pyR�s
cCs-td�t|_t|j_|j�dS(Nsterminating pool(RR�R<RIRU(R((s*/sys/lib/python2.7/multiprocessing/pool.pyt terminate�s
cCsntd�|jttfks%t�|jj�|jj�|jj�x|j D]}|j�qVWdS(Nsjoining pool(
RR<R�R�RRIR\RORRRD(RR�((s*/sys/lib/python2.7/multiprocessing/pool.pyR\�s
cCsWtd�|jj�x9|j�rR|jj�rR|jj�tjd�qWdS(Ns7removing tasks from inqueue until task handler finishedi( Rt_rlocktacquiretis_aliveRR�RhR�R�(R%ttask_handlerR�((s*/sys/lib/python2.7/multiprocessing/pool.pyt_help_stuff_finish�s
c
Cs�td�t|_t|_td�|j||t|��|j�sct|�dksct�t|_|jd�td�t j
�|k r�|jd�n|r�|dd�r�d�x-|D]"} | j
dkr�| j�q�q�Wntd�t j
�|k r$|jd�ntd �t j
�|k rP|jd�n|r�t|dd�r�td
�x;|D]0} | j�rztd| j�| j�qzqzWndS(Nsfinalizing pools&helping task handler/workers to finishisjoining worker handlerg}Ô%��R�sterminating workerssjoining task handlersjoining result handlersjoining pool workersscleaning up worker %d(RR�R<R�RZR�RRRRFR�R\RR[R�tpid(
tclsR�R%R&R�tworker_handlerR�tresult_handlerR�R�((s*/sys/lib/python2.7/multiprocessing/pool.pyRS�s8
$
N((((RRRRRRR^RERdR7RjRRxRzRiRktstaticmethodRHRLRPRvR�RR�R\R�tclassmethodRS(((s*/sys/lib/python2.7/multiprocessing/pool.pyR�s0 :
*: R{cBsDeZd�Zd�Zd�Zdd�Zdd�Zd�ZRS(cCsStjtj��|_tj�|_||_t|_ ||_
|||j<dS(N(RFt ConditiontLockt_condtjob_countertnextRnR:R$t_readyt _callback(RR�R|((s*/sys/lib/python2.7/multiprocessing/pool.pyRs cCs|jS(N(R�(R((s*/sys/lib/python2.7/multiprocessing/pool.pytreadyscCs|jst�|jS(N(R�Rt_success(R((s*/sys/lib/python2.7/multiprocessing/pool.pyt
successfulscCsB|jj�z |js,|jj|�nWd|jj�XdS(N(R�R�R�twaittrelease(Rttimeout((s*/sys/lib/python2.7/multiprocessing/pool.pyR�s
cCs<|j|�|jst�n|jr/|jS|j�dS(N(R�R�RR�t_value(RR�((s*/sys/lib/python2.7/multiprocessing/pool.pyR's
cCs�|\|_|_|jr7|jr7|j|j�n|jj�zt|_|jj�Wd|jj�X|j |j
=dS(N(R�R�R�R�R�R"R�tnotifyR�R:Rn(RR-R�((s*/sys/lib/python2.7/multiprocessing/pool.pyR�0s
N( RRRR�R�RR�RR�(((s*/sys/lib/python2.7/multiprocessing/pool.pyR{s R�cBseZd�Zd�ZRS(cCstj|||�t|_dg||_||_|dkr`d|_t|_||j =n||t
||�|_dS(Ni(R{RR"R�RR�t
_chunksizet_number_leftR�Rntbool(RR�RmtlengthR|((s*/sys/lib/python2.7/multiprocessing/pool.pyRDs
cCs|\}}|r�||j||j|d|j+|jd8_|jdkr|jrn|j|j�n|j|j=|jj�zt|_ |jj
�Wd|jj�XqnWt|_
||_|j|j=|jj�zt|_ |jj
�Wd|jj�XdS(Nii(R�R�R�R�R:RnR�R�R"R�R�R�R$R�(RR-tsuccess_resulttsuccessR0((s*/sys/lib/python2.7/multiprocessing/pool.pyR�Ps*"
(RRRR�(((s*/sys/lib/python2.7/multiprocessing/pool.pyR�Bs RscBs>eZd�Zd�Zdd�ZeZd�Zd�ZRS(cCsktjtj��|_tj�|_||_tj �|_
d|_d|_
i|_|||j<dS(Ni(RFR�R�R�R�R�RnR:tcollectionstdequet_itemst_indexRt_lengtht _unsorted(RR�((s*/sys/lib/python2.7/multiprocessing/pool.pyRqs cCs|S(N((R((s*/sys/lib/python2.7/multiprocessing/pool.pyt__iter__{scCs�|jj�z�y|jj�}Wn�tk
r�|j|jkrNt�n|jj|�y|jj�}Wq�tk
r�|j|jkr�t�nt �q�XnXWd|jj
�X|\}}|r�|S|�dS(N(R�R�R�tpopleftt
IndexErrorR�R�t
StopIterationR�RR�(RR�RrR�R((s*/sys/lib/python2.7/multiprocessing/pool.pyR�~s&
cCs�|jj�z�|j|kr�|jj|�|jd7_xJ|j|jkr�|jj|j�}|jj|�|jd7_qAW|jj�n
||j|<|j|jkr�|j |j
=nWd|jj�XdS(Ni(R�R�R�R�R`R�tpopR�R�R:RnR�(RR-R�((s*/sys/lib/python2.7/multiprocessing/pool.pyR��s
cCs^|jj�z<||_|j|jkrH|jj�|j|j=nWd|jj�XdS(N(R�R�R�R�R�R:RnR�(RR�((s*/sys/lib/python2.7/multiprocessing/pool.pyRu�s
N( RRRR�RR�t__next__R�Ru(((s*/sys/lib/python2.7/multiprocessing/pool.pyRsos
RycBseZd�ZRS(cCst|jj�zR|jj|�|jd7_|jj�|j|jkr^|j|j=nWd|jj �XdS(Ni(
R�R�R�R`R�R�R�R:RnR�(RR-R�((s*/sys/lib/python2.7/multiprocessing/pool.pyR��s
(RRR�(((s*/sys/lib/python2.7/multiprocessing/pool.pyRy�st
ThreadPoolcBsBeZddlmZdddd�Zd�Zed��ZRS(i(RcCstj||||�dS(N(RR(RRVR'R(((s*/sys/lib/python2.7/multiprocessing/pool.pyR�scCs@tj�|_tj�|_|jj|_|jj|_dS(N(R8RTRNRRMRRQ(R((s*/sys/lib/python2.7/multiprocessing/pool.pyR7�scCsW|jj�z5|jj�|jjdg|�|jj�Wd|jj�XdS(N(t not_emptyR�tqueuetcleartextendRt
notify_allR�(R%R�R�((s*/sys/lib/python2.7/multiprocessing/pool.pyR��s
N(( RRtdummyRRRR7R�R�(((s*/sys/lib/python2.7/multiprocessing/pool.pyR��s (t__all__RFR8R�R�R�tmultiprocessingRRRtmultiprocessing.utilRRR;R�R�tcountR�RR#R RR3tobjectRR{tAsyncResultR�RsRyR�(((s*/sys/lib/python2.7/multiprocessing/pool.pyt<module>#s, *�.-I
|