+
    i   c                   s   R R.t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^RI
Ht ^RI
HtHt ^RIHt RtRtRtR	t]P(                  ! 4       tR
 tR t ! R R]4      t ! R R4      tR t ! R R]4      tR!R ltR t ! R R]4      t  ! R R ]!4      t" ! R R]!4      t#]#t$ ! R R]#4      t% ! R R]!4      t& ! R R]&4      t' ! R  R]"4      t(R# )"Pool
ThreadPoolN)util)get_contextTimeoutError)waitINITRUNCLOSE	TERMINATEc                 s&    \        \        V !  4      # N)listmapargs   &-/usr/lib64/python3.14/multiprocessing/pool.pymapstarr   /   s    T
    c                 s^    \        \        P                  ! V ^ ,          V ^,          4      4      # )    )r   	itertoolsstarmapr   r   r   starmapstarr   2   s"    	!!$q'47344r   c                   s,   a  ] tR t^9t o R tR tRtV tR# )RemoteTracebackc                s    Wn         R # r
   tb)selfr      &&r   __init__ZRemoteTraceback.__init__:   s    r   c                s    V P                   # r
   r   r   r   r   __str__ZRemoteTraceback.__str__<   s    wwr   r   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes____classdictcell____classdict__   @r   r   r   9   s      r   r   c                   s,   a  ] tR t^?t o R tR tRtV tR# )ExceptionWithTracebackc                s    \         P                  ! \        V4      W4      pR P                  V4      pWn        RV,          V n        R# ) z

"""
%s"""N)	tracebackZformat_exceptionZtypejoinexcr   )r   r,   r      &&&r   r   ZExceptionWithTraceback.__init__@   s6    ''S	3;WWR[ 2%r   c                s>    \         V P                  V P                  33# r
   )rebuild_excr,   r   r   r   r   
__reduce__Z!ExceptionWithTraceback.__reduce__E   s    TXXtww///r   r,   r   N)r   r    r!   r"   r   r/   r#   r$   r%   r'   r   r(   r(   ?   s     &
0 0r   r(   c                 s&    \        V4      V n        V # r
   )r   Z	__cause__r0   r   r   r.   r.   H   s    #B'CMJr   c                   sB   a a ] tR t^Pt oRtV 3R ltR tR tRtVt	V ;t
# )MaybeEncodingErrorzRWraps possible unpickleable errors, so they can be
safely sent through the socket.c                s   < \        V4      V n        \        V4      V n        \        \        V `  V P                  V P                  4       R # r
   )Zreprr,   valuesuperr1   r   )r   r,   r2   	__class__s   &&&r   r   ZMaybeEncodingError.__init__T   s3    9%[
 $04::Fr   c                s@    R V P                   : RV P                  : R2# )zError sending result: 'z'. Reason: 'Z')r2   r,   r   r   r   r   ZMaybeEncodingError.__str__Y   s    =AZZ=AXXG 	Gr   c                s@    R V P                   P                  : RV : R2# )<z: >)r4   r   r   r   r   __repr__ZMaybeEncodingError.__repr__]   s    !^^44d;;r   )r,   r2   )r   r    r!   r"   __doc__r   r   r7   r#   r$   __classcell__r4   r&      @@r   r1   r1   P   s      'G
G< <r   r1   c                 s   Ve8   \        V\        4      '       d   V^8  g   \        RP                  V4      4      hVP                  pV P
                  p\        V R4      '       d5   V P                  P                  4        VP                  P                  4        Ve   V! V!   ^ pVe   V'       d\   W8  dV    V! 4       p	T	f   \        P                  ! R4       M2T	w  rrp RT! T/ TB 3p T! YT34       R ;p	;p
;p;p;rT^,          pKg  \        P                  ! RV,          4       R #   \        \        3 d    \        P                  ! R4        KI  i ; i  \         d7   pT'       d!   T\        Jd   \!        TTP"                  4      pRT3p R p?LR p?ii ; i  \         dG   p\%        TT^,          4      p\        P                  ! RT,          4       T! YRT334        R p?LR p?ii ; i)	NzMaxtasks {!r} is not valid_writerz)worker got EOFError or OSError -- exitingzworker got sentinel -- exitingTFz0Possible encoding error while sending result: %szworker exiting after %d tasks)
isinstanceintAssertionErrorformatputgethasattrr<   close_readerEOFErrorOSErrorr   debug	Exception_helper_reraises_exceptionr(   Z__traceback__r1   )inqueueoutqueueinitializerinitargsZmaxtaskswrap_exceptionrA   rB   Z	completedtaskjobifuncr   kwdsresulteZwrappeds   &&&&&&            r   workerrW   a   s   z(C'@'@+3q=9@@JKK
,,C
++Cw	"" XI

xI,@	5D
 <JJ78#' D	 D$/$/0F
	, ! 4877s7V7d7TQ	JJ.:;3 '" 	JJBC	  	 $.H"H*1aoo>QZF	   	,(F1I6GJJI %)*++		,sB   9D, "
E -
F ,'EEF%,FFG/)<G**G/c                s    V h)z@Pickle-able helper function for use by _guarded_task_generation. )Zexr   r   rJ   rJ      s    
Hr   c                   sJ   a a ] tR t^t oRtRR/V 3R lltV 3R ltRtVtV ;t	# )
_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.
notifierNc              s4   < Wn         \        SV `  ! V/ VB  R # r
   )rZ   r3   r   )r   rZ   r   rT   r4   s   "$*,r   r   Z_PoolCache.__init__   s     $'$'r   c                sp   < \         SV `  V4       V '       g   V P                  P                  R 4       R # R # r
   )r3   __delitem__rZ   rA   )r   itemr4   s   &&r   r[   Z_PoolCache.__delitem__   s,    D! MMd# r   rZ   )
r   r    r!   r"   r8   r   r[   r#   r$   r9   r:   r;   r   rY   rY      s      ($ (
$ 
$r   rY   c                   s  a  ] tR t^t o RtRt]R 4       tR)R lt]	P                  ]3R ltR tR t]R	 4       t]R
 4       tR t]R 4       t]R 4       tR tR tR(/ 3R ltR*R ltR*R ltR+R ltR tR,R ltR,R ltR(/ RR3R ltR+R ltR+R lt]R*R l4       t ]!R 4       t"]R 4       t#]R 4       t$]R 4       t%R t&R  t'R! t(R" t)]R# 4       t*]!R$ 4       t+R% t,R& t-R't.V t/R# )-r    zK
Class which supports an async version of applying functions to arguments.
Tc                s&    V P                   ! V/ VB # r
   Process)ctxr   rT   s   &*,r   r_   ZPool.Process   s    {{D)D))r   Nc                s   . V n         \        V n        T;'       g    \        4       V n        V P                  4        \        P                  ! 4       V n        V P                  P                  4       V n	        \        V P                  R 7      V n        W@n        W n        W0n        Vf    \        P                   ! 4       ;'       g    ^pV^8  d   \#        R4      hVe)   \%        V\&        4      '       d   V^ 8:  d   \#        R4      hVe   \)        V4      '       g   \+        R4      hWn         V P/                  4        T P9                  4       p\:        P<                  ! \>        P@                  T P                  T P                  T P                  T PB                  T P,                  T P                   T PD                  T PF                  T P                  T P                  T P                  T PH                  YpP                  3R7      T n%        RT PJ                  n&        \N        T PJ                  n        T PJ                  PQ                  4        \:        P<                  ! \>        PR                  T P                  T PT                  T PF                  T P                   T P                  3R7      T n+        RT PV                  n&        \N        T PV                  n        T PV                  PQ                  4        \:        P<                  ! \>        PX                  T PF                  T PZ                  T P                  3R7      T n.        RT P\                  n&        \N        T P\                  n        T P\                  PQ                  4        \^        P`                  ! Y Pb                  T P                  T PD                  T PF                  T P                   T P                  T PJ                  T PV                  T P\                  T P                  3	^R7      T n2        \N        T n        R#   \0         dY    T P                    F#  pTP2                  e   K  TP5                  4        K%  	  T P                    F  pTP7                  4        K  	  h i ; i)r]   Nz&Number of processes must be at least 1z/maxtasksperchild must be a positive int or Nonezinitializer must be a callableZtargetr   T)r   Zexitpriority)3_poolr   _stater   _ctx_setup_queuesqueueSimpleQueue
_taskqueue_change_notifierrY   _cache_maxtasksperchild_initializer	_initargsosZprocess_cpu_count
ValueErrorr=   r>   ZcallableZ	TypeError
_processes_repopulate_poolrI   exitcode	terminater+   _get_sentinels	threadingZThreadr    _handle_workersr_   _inqueue	_outqueue_wrap_exception_worker_handlerdaemonr   start_handle_tasks
_quick_put_task_handler_handle_results
_quick_get_result_handlerr   ZFinalize_terminate_pool
_terminate)r   	processesrM   rN   maxtasksperchildZcontextp	sentinelss   &&&&&&  r   r   ZPool.__init__   sO    
,,{}	++- !%		 5 5 7 $*?*?@!1'!,,.33!Iq=EFF'.448HA8M !RSS"8K+@+@<==#	!!# '')	(//''++t		4<<//4::t}}dnn##T^^T5K5K&&	3H3HJ  '+#&)#""$ '--%%//4??DNN**dkk+
 %)!$'!  "(//''..$//4;;?  '+#&)#""$--&&//4==$..$**'')=)=t?Q?Q&&5  ]  	ZZ::%KKM   ZZ  	s   *P
 
%Q-49Q-c                s    V P                   V8X  dB   V! R V : 2\        V R7       \        V RR4      e   V P                  P	                  R4       R# R# R# )z&unclosed running multiprocessing pool )Zsourceri   N)rc   ZResourceWarningZgetattrri   rA   )r   Z_warnr   r-   r   __del__ZPool.__del__
  sT    ;;#:4(C!$0t/6B%%))$/ C r   c           
     s    V P                   pR VP                   RVP                   RV P                   R\	        V P
                  4       R2	# )r5   Z.z state=z pool_size=r6   )r4   r    r!   rc   lenrb   )r   cls   & r   r7   ZPool.__repr__  sQ    nnCNN#1S%5%5$6 7 & _-Q0 	1r   c                sj    V P                   P                  .pV P                  P                  .p. VOVO# r
   )rx   rE   ri   )r   Ztask_queue_sentinelsZself_notifier_sentinels   &  r   rt   ZPool._get_sentinels  s<     $ 6 67#'#8#8#@#@"A@%@(?@@r   c                sl    V  Uu. uF#  p\        VR 4      '       g   K  VP                  NK%  	  up# u upi )sentinel)rC   r   )workersrW   r   r   _get_worker_sentinelsZPool._get_worker_sentinels  s<     8 %+"6:6  8 	8 8s   11c                s    Rp\        \        \        V 4      4      4       FL  pW,          pVP                  f   K  \        P
                  ! RV,          4       VP                  4        RpW KN  	  V# )zCleanup after any worker processes which have exited due to reaching
their specified lifetime.  Returns True if any workers were cleaned up.
Fcleaning up worker %dT)Zreversedranger   rr   r   rH   r+   )poolZcleanedrR   rW   s   &   r   _join_exited_workersZPool._join_exited_workers!  s^    
 %D	*+AWF*

2Q67G , r   c                s    V P                  V P                  V P                  V P                  V P                  V P
                  V P                  V P                  V P                  V P                  V P                  4
      # r
   )_repopulate_pool_staticrd   r_   rp   rb   rw   rx   rl   rm   rk   ry   r   r   r   rq   ZPool._repopulate_pool1  s_    ++DIIt||,0OO,0JJ,0NND<M<M,0NN,0,B,B,0,@,@B 	Br   c
                s.   \        V\        V4      ,
          4       Fu  p
V! V \        WEVWxV	3R7      pVP                  P	                  RR4      Vn        RVn        VP                  4        VP                  V4       \        P                  ! R4       Kw  	  R# )zpBring the number of pool processes up to the specified number,
for use after reaping workers which have exited.
ra   r_   Z
PoolWorkerTzadded workerN)
r   r   rW   ZnameZreplacer{   r|   appendr   rH   )r`   r_   r   r   rK   rL   rM   rN   r   rO   rR   Zws   &&&&&&&&&&  r   r   ZPool._repopulate_pool_static:  sz     y3t9,-AF%)&,./A
 VV^^I|<AFAHGGIKKNJJ~& .r   c
                st    \         P                  V4      '       d   \         P                  WW#WEVWxV	4
       R# R# )zEClean up any exited workers and start replacements for them.
        N)r    r   r   )
r`   r_   r   r   rK   rL   rM   rN   r   rO   s
   &&&&&&&&&&r   _maintain_poolZPool._maintain_poolM  s7     $$T**((y)0K)1)79 +r   c                s   V P                   P                  4       V n        V P                   P                  4       V n        V P                  P                  P
                  V n        V P                  P                  P                  V n	        R # r
   )
rd   rg   rw   rx   r<   Zsendr~   rE   recvr   r   r   r   re   ZPool._setup_queuesY  sX    		--/..0--//44..0055r   c                sF    V P                   \        8w  d   \        R 4      hR# )zPool not runningN)rc   r   ro   r   r   r   _check_runningZPool._check_running_  s    ;;#/00 r   c                sB    V P                  WV4      P                  4       # )z<
Equivalent of `func(*args, **kwds)`.
Pool must be running.
)apply_asyncrB   )r   rS   r   rT      &&&&r   applyZ
Pool.applyc  s     
 D15577r   c                L    V P                  W\        V4      P                  4       # )z`
Apply `func` to each element in `iterable`, collecting the results
in a list that is returned.
)
_map_asyncr   rB   r   rS   iterable	chunksizer   r   r   ZPool.mapj  s     
 tw	BFFHHr   c                r   )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   r   rB   r   r   r   r   ZPool.starmapq  s      t{IFJJLLr   c                s2    V P                  W\        VWE4      # )z-
Asynchronous version of `starmap()` method.
)r   r   r   rS   r   r   callbackerror_callback   &&&&&&r   starmap_asyncZPool.starmap_asyncy  s    
 t{I'9 	9r   c              #  s   "    Rp\        V4       F  w  rEWW%3/ 3x  K  	  R#   \         d!   pTX^,           \        T3/ 3x   Rp?R# Rp?ii ; i5i)zProvides a generator of tasks for imap and imap_unordered with
appropriate handling for iterables which throw exceptions during
iteration.N)Z	enumeraterI   rJ   )r   Z
result_jobrS   r   rR   xrV   s   &&&&   r   _guarded_task_generationZPool._guarded_task_generation  s\     	JA!(+!dD"55 , 	Jqs$>bIII	Js*   A$ AAA
A
AAc                   V P                  4        V^8X  dO   \        V 4      pV P                  P                  V P	                  VP
                  W4      VP                  34       V# V^8  d   \        RP                  V4      4      h\        P                  WV4      p\        V 4      pV P                  P                  V P	                  VP
                  \        V4      VP                  34       R V 4       # )z@
Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
zChunksize must be 1+, not {0:n}c              3   4   "   T F  q F  q"x  K  	  K  	  R # 5ir
   rX   Z.0Zchunkr\   r   r   	<genexpr>ZPool.imap.<locals>.<genexpr>       ?fUDDf   )r   IMapIteratorrh   rA   r   _job_set_lengthro   r@   r    
_get_tasksr   r   rS   r   r   rU   task_batches   &&&&  r   imapZ	Pool.imap  s     	>!$'FOO11&++tN&&
 M1} 5<<!#$ $  ??49EL!$'FOO11&++292>@ &&	 @f??r   c                r   )z<
Like `imap()` method but ordering of results is arbitrary.
zChunksize must be 1+, not {0!r}c              3   r   r
   rX   r   r   r   r   Z&Pool.imap_unordered.<locals>.<genexpr>  r   r   )r   IMapUnorderedIteratorrh   rA   r   r   r   ro   r@   r    r   r   r   r   r   imap_unorderedZPool.imap_unordered  s     	>*40FOO11&++tN&&
 M1} 5<<YGI I??49EL*40FOO11&++292>@ &&	 @f??r   c                s    V P                  4        \        WV4      pV P                  P                  VP                  ^ WV3.R34       V# )z+
Asynchronous version of `apply()` method.
N)r   ApplyResultrh   rA   r   )r   rS   r   rT   r   r   rU   s   &&&&&& r   r   ZPool.apply_async  sH    
 	T^<v{{At4@A4HIr   c                s2    V P                  W\        W4V4      # )z)
Asynchronous version of `map()` method.
)r   r   r   r   r   	map_asyncZPool.map_async  s    
 tw	 	r   c                s   V P                  4        \        VR4      '       g   \        V4      pVfC   \        \	        V4      \	        V P
                  4      ^,          4      w  rGV'       d
   V^,          p\	        V4      ^ 8X  d   ^ p\        P                  WV4      p\        W\	        V4      VVR7      p	V P                  P                  V P                  V	P                  VV4      R34       V	# )zI
Helper function to implement map, starmap and their async counterparts.
Z__len__Nr   )r   rC   r   Zdivmodr   rb   r    r   	MapResultrh   rA   r   r   )
r   rS   r   Zmapperr   r   r   Zextrar   rU   s
   &&&&&&&   r   r   ZPool._map_async  s    
 	x++H~H%c(mS_q5HIIQ	x=AItyA4CM8*8:--fkk.4.:< 		
 r   c                sn    \        WR 7       VP                  4       '       g   VP                  4        K(  R# ))timeoutN)r   ZemptyrB   )r   change_notifierr   r-   r   _wait_for_updatesZPool._wait_for_updates  s*    Y(!''))! *r   c                s`   \         P                  ! 4       pVP                  \        8X  g   V'       dU   VP                  \        8w  d@   V P                  W4WVVWV
W4
       . V P                  V4      OVOpV P                  VV4       Kq  VP                  R 4       \        P                  ! R4       R # )Nzworker handler exiting)ru   current_threadrc   r   r	   r   r   r   rA   r   rH   )r   cache	taskqueuer`   r_   r   r   rK   rL   rM   rN   r   rO   r   r   threadZcurrent_sentinelss   &&&&&&&&&&&&&&&  r   rv   ZPool._handle_workers  s    
 ))+ mms"u)1KsYg'h/A !O#";";D"A NI N!!"3_Ed

+,r   c                s   \         P                  ! 4       p\        V P                  R 4       F  w  rgR p V F9  pVP                  \
        8w  d   \        P                  ! R4        MU V! V4       K;  	  V'       d9   \        P                  ! R4       V'       d
   V^,          MR
pV! V^,           4        R ;p;rjK   R ;p;rj M	  \        P                  ! R4        \        P                  ! R4       VP                  R 4       \        P                  ! R4       V F  pV! R 4       K  	  \        P                  ! R	4       R #   \         dJ   p	TR,          w  r YJ,          P                  TRT	34        R p	?	EKD    \         d
      R p	?	EKW  i ; iR p	?	ii ; i  R ;p;rji ; i  \         d    \        P                  ! R4        Li ; i)Nz'task handler found thread._state != RUN:Ni   NFzdoing set_length()ztask handler got sentinelz/task handler sending sentinel to result handlerz(task handler sending sentinel to workersz/task handler got OSError when sending sentinelsztask handler exitingr   )ru   r   iterrB   rc   r   r   rH   rI   _setKeyErrorrA   rG   )r   rA   rL   r   r   r   ZtaskseqZ
set_lengthrP   rV   rQ   Zidxr   s   &&&&&        r   r}   ZPool._handle_tasks  s   ))+#'	t#<GD,#D}}+

#LM!D	 $ "

#78)-d1g2"37+ (,++w '+++w1 $=4 JJ23
	JJJHILL JJABD	 
 	

)*= % !#'8!!JOOC%<<' ! !	! (,++w  	JJJHI	Jsx   2F'E/F;FFAF# FFE:3F:F	FFF	FFFF #!GGc                s0   \         P                  ! 4       p  V! 4       pTP                  \        8w  d   \        P
                  ! R4       M?Tf   \        P
                  ! R4       M$Tw  rVp Y%,          P                  Yg4       R;p;rWKt  T'       d^   TP                  \        8w  dI    T! 4       pTf   \        P
                  ! R4       KA  Tw  rVp Y%,          P                  Yg4       R;p;rWKe  \        T R4      '       dT   \        P
                  ! R4        \        ^
4       F,  pT P                  P                  4       '       g    MT! 4        K.  	   \        P
                  ! R\        T4      TP                  4       R#   \        \        3 d    \        P
                  ! R4        R# i ; i  \         d     EL:i ; i  \        \        3 d    \        P
                  ! R4        R# i ; i  \         d     ELi ; i  \        \        3 d     Li ; i)	   z.result handler got EOFError/OSError -- exitingNz,result handler found thread._state=TERMINATEzresult handler got sentinelz&result handler ignoring extra sentinelrE   z"ensuring that outqueue is not fullz7result handler exiting: len(cache)=%s, thread._state=%s)ru   r   rG   rF   r   rH   rc   r   r   r   r	   rC   r   rE   pollr   )rL   rB   r   r   rP   rQ   rR   objs   &&&     r   r   ZPool._handle_results=  s   ))+u
 }}#

IJ|

89KCC
'  $#D#32u
 |

CDKCC
'  $#D#38Y''JJ;<rA#++0022E # 	

L%j&--	)e X& 

KL    X& 

KL   X& s_   F ,F/ (G G/ /H H 'F,+F,/F>=F>'G,+G,/G>=G>HHc              #  s   "   \        V4      p \        \        P                  ! W4      4      pV'       g   R# W3x  K1  5ir   N)r   Ztupler   Zislice)rS   Zitsizer      &&& r   r   ZPool._get_tasksy  s3     "Xi&&r01A)Os   =?c                s    \        R 4      h)z:pool objects cannot be passed between processes or pickled)ZNotImplementedErrorr   r   r   r/   ZPool.__reduce__  s    !J 	r   c                s    \         P                  ! R 4       V P                  \        8X  d>   \        V n        \        V P
                  n        V P                  P                  R4       R# R# )zclosing poolN)r   rH   rc   r   r   rz   ri   rA   r   r   r   rD   Z
Pool.close  sH    

>";;#DK*/D  '!!%%d+ r   c                sh    \         P                  ! R 4       \        V n        V P	                  4        R# )zterminating poolN)r   rH   r	   rc   r   r   r   r   rs   ZPool.terminate  s     

%&r   c                s   \         P                  ! R 4       V P                  \        8X  d   \	        R4      hV P                  \
        \        39  d   \	        R4      hV P                  P                  4        V P                  P                  4        V P                  P                  4        V P                   F  pVP                  4        K  	  R# )zjoining poolzPool is still runningzIn unknown stateN)r   rH   rc   r   ro   r   r	   rz   r+   r   r   rb   )r   r   r   r   r+   Z	Pool.join  s    

>";;#455[[	 22/00!!#!!!#AFFH r   c                s:   \         P                  ! R 4       V P                  P                  4        VP	                  4       '       dU   V P
                  P                  4       '       d3   V P
                  P                  4        \        P                  ! ^ 4       Kh  R# R# )z7removing tasks from inqueue until task handler finishedN)
r   rH   Z_rlockZacquireis_aliverE   r   r   timesleep)rK   task_handlerr   r-   r   _help_stuff_finishZPool._help_stuff_finish  sf     	

LM ##%%'//*>*>*@*@OO  "JJqM +A%r   c
                s   \         P                  ! R 4       \        Vn        VP	                  R4       \        Vn        \         P                  ! R4       V P                  W'\        V4      4       VP                  4       '       g   \        V	4      ^ 8w  d   \        R4      h\        Vn        VP	                  R4       VP	                  R4       \         P                  ! R4       \        P                  ! 4       VJd   VP                  4        V'       dY   \        V^ ,          R4      '       d@   \         P                  ! R4       V F#  p
V
P                  e   K  V
P                  4        K%  	  \         P                  ! R4       \        P                  ! 4       VJd   VP                  4        \         P                  ! R4       \        P                  ! 4       VJd   VP                  4        V'       d   \        V^ ,          R4      '       dq   \         P                  ! R	4       V FR  p
V
P                  4       '       g   K  \         P                  ! R
V
P                  ,          4       V
P                  4        KT  	  R# R# R# )zfinalizing poolNz&helping task handler/workers to finishz/Cannot have cache with result_handler not alivezjoining worker handlerrs   zterminating workerszjoining task handlerzjoining result handlerzjoining pool workersr   )r   rH   r	   rc   rA   r   r   r   r?   ru   r   r+   rC   rr   rs   Zpid)r   r   rK   rL   r   r   Zworker_handlerr   Zresult_handlerr   r   s   &&&&&&&&&& r   r   ZPool._terminate_pool  s    	

$%
 !*D!'

;<wc$i@''))E
a AC C !*D!T 	

+,##%^;! GDG[11JJ,-::%KKM  	

)*##%\9

+,##%^;!GDG[11JJ-.::<<JJ6>?FFH	  24r   c                s&    V P                  4        V # r
   )r   r   r   r   	__enter__ZPool.__enter__  s    r   c                s&    V P                  4        R # r
   )rs   )r   Zexc_typeZexc_valZexc_tbr   r   __exit__ZPool.__exit__  s    r   )rj   ri   rd   rm   rl   rw   rk   rx   rb   rp   r   r~   r   rc   r   rh   r   rz   rX   )NNrX   NNr
   )NNN)r   )0r   r    r!   r"   r8   ry   staticmethodr_   r   warningsZwarnr   r   r7   rt   r   r   rq   r   r   re   r   r   r   r   r   r   r   r   r   r   r   r   classmethodrv   r}   r   r   r/   rD   rs   r+   r   r   r   r   r#   r$   r%   r'   r   r    r       s     O* *Of %MMs 01A
 8 8  B ' '$ 	9 	961  " 8IM9	J@:@8 &(b4: " "
 - -( ++ ++Z 9) 9)v  
,

   3 3j r   c                   sp   a  ] tR tRt o R tR tR tR
R ltR
R ltR t	]
! ]P                  4      tR	tV tR# )r   i  c                s    Wn         \        P                  ! 4       V n        \	        \
        4      V n        VP                  V n        W n        W0n	        W P                  V P                  &   R # r
   )
rb   ru   ZEvent_eventnextjob_counterr   rj   	_callback_error_callback)r   r   r   r   r   r   r   ZApplyResult.__init__  sG    
oo'%	kk!-!%DIIr   c                s6    V P                   P                  4       # r
   )r   Zis_setr   r   r   readyZApplyResult.ready  s    {{!!##r   c                sz    V P                  4       '       g   \        R P                  V 4      4      hV P                  # )z{0!r} not ready)r   ro   r@   _successr   r   r   
successfulZApplyResult.successful  s.    zz||.55d;<<}}r   Nc                s<    V P                   P                  V4       R # r
   )r   r   r   r   r   r   r   ZApplyResult.wait  s    !r   c                s    V P                  V4       V P                  4       '       g   \        hV P                  '       d   V P                  # V P                  hr
   )r   r   r   r   _valuer   r   r   rB   ZApplyResult.get  s<    		'zz||===;;++r   c                s   Vw  V n         V n        V P                  '       d.   V P                   '       d   V P                  V P                  4       V P                  '       d.   V P                   '       g   V P                  V P                  4       V P                  P                  4        V P                  V P                   R V n        R # r
   )	r   r   r   r   r   setrj   r   rb   r   rR   r   r-   r   r   ZApplyResult._set  s|    %("t{>>>dmmmNN4;;'  -KK		"
r   )rj   r   r   r   r   rb   r   r   r
   )r   r    r!   r"   r   r   r   r   rB   r   r   typesZGenericAliasZ__class_getitem__r#   r$   r%   r'   r   r   r     s6     &$
" $E$6$67r   r   c                   s,   a  ] tR tRt o R tR tRtV tR# )r   i  c                s6   \         P                  WVVR 7       RV n        R.V,          V n        W n        V^ 8:  d;   ^ V n        V P                  P                  4        V P                  V P                   R# W2,          \        W2,          4      ,           V n        R# )r   TN)r   r   r   r   
_chunksize_number_leftr   r   rj   r   Zbool)r   r   r   lengthr   r   r   r   r   ZMapResult.__init__  sz    T,: 	 	<fvo#> !DKKOODII& & 1D9K4L LDr   c                s   V ;P                   ^,          un         Vw  r4V'       d   V P                  '       d   W@P                  WP                  ,          V^,           V P                  ,          % V P                   ^ 8X  dh   V P                  '       d   V P	                  V P                  4       V P
                  V P                   V P                  P                  4        RV n	        R# R# V'       g    V P                  '       d   RV n        W@n        V P                   ^ 8X  dh   V P                  '       d   V P                  V P                  4       V P
                  V P                   V P                  P                  4        RV n	        R# R# )r   NF)r   r   r   r   r   rj   r   r   r   rb   r   )r   rR   Zsuccess_resultsuccessrU   s   &&&  r   r   ZMapResult._set)  s   Q(t}}}CIKK//)1Q3*?@  A%>>>NN4;;/KK		*!!
 & t}}} %$  A%'''((5KK		*!!
 &r   )r   r   rb   r   r   N)r   r    r!   r"   r   r   r#   r$   r%   r'   r   r   r     s     M" "r   r   c                   sF   a  ] tR tRt o R tR tR	R lt]tR tR t	Rt
V tR# )
r   iE  c                sF   Wn         \        P                  ! \        P                  ! 4       4      V n        \        \        4      V n        VP                  V n        \        P                  ! 4       V n        ^ V n        RV n        / V n        W P                  V P                  &   R# )r   N)rb   ru   Z	ConditionZLock_condr   r   r   rj   collectionsZdeque_items_index_length	_unsorted)r   r   r   r   r   ZIMapIterator.__init__G  sl    
(()9:
%	kk!'')!%DIIr   c                s    V # r
   rX   r   r   r   __iter__ZIMapIterator.__iter__R  s    r   Nc                s   V P                   ;_uu_ 4         V P                  P                  4       pR R R 4       Xw  r4T'       d   T# Th  \         d    T P                  T P
                  8X  d   R T n        \        R hT P                   P                  T4        T P                  P                  4       p L  \         d2    T P                  T P
                  8X  d   R T n        \        R h\        R hi ; ii ; i  + '       g   i     L; ir
   )
r   r   ZpopleftZ
IndexErrorr   r   rb   ZStopIterationr   r   )r   r   r\   r   r2   s   &&   r   r   ZIMapIterator.nextU  s    ZZZ1{{**,   L!  1;;$,,.!%DJ'T1

(1;;..0D! 1{{dll2%)
+5&D0	11 Zs5   C8A		AC5B53C85<C1	1C55C88D	c                s   V P                   ;_uu_ 4        V P                  V8X  d   V P                  P                  V4       V ;P                  ^,          un        V P                  V P                  9   d\   V P                  P                  V P                  4      pV P                  P                  V4       V ;P                  ^,          un        Kv  V P                   P                  4        MW P                  V&   V P                  V P                  8X  d   V P                  V P                   RV n
        RRR4       R#   + '       g   i     R# ; ir   )r   r   r   r   r   Zpopnotifyr   rj   r   rb   r   r-   r   r   ZIMapIterator._setm  s    ZZZ{{a""3'q kkT^^3..,,T[[9CKK&&s+KK1$K

!!#$'q!{{dll*KK		*!
 ZZZs   DD==E	c                s   V P                   ;_uu_ 4        Wn        V P                  V P                  8X  d9   V P                   P                  4        V P                  V P
                   R V n        R R R 4       R #   + '       g   i     R # ; ir
   )r   r   r   r   rj   r   rb   )r   r   r   r   r   ZIMapIterator._set_length~  sS    ZZZ!L{{dll*

!!#KK		*!
 ZZZs   AA99B
	)rj   r   r   r   r   r   rb   r   r
   )r   r    r!   r"   r   r   r   Z__next__r   r   r#   r$   r%   r'   r   r   r   E  s*     	&, H""" "r   r   c                   s&   a  ] tR tRt o R tRtV tR# )r   i  c                sv   V P                   ;_uu_ 4        V P                  P                  V4       V ;P                  ^,          un        V P                   P	                  4        V P                  V P
                  8X  d   V P                  V P                   RV n        RRR4       R#   + '       g   i     R# ; ir   )	r   r   r   r   r   r   rj   r   rb   r   r-   r   r   ZIMapUnorderedIterator._set  sn    ZZZKKs#KK1KJJ{{dll*KK		*!
 ZZZs   BB''B8	)rb   N)r   r    r!   r"   r   r#   r$   r%   r'   r   r   r     s     " "r   r   c                   sp   a  ] tR tRt o Rt]R 4       tRR ltR tR t	]R 4       t
]R	 4       tR
 tRtV tR# )r   i  Fc                s    ^RI Hp V! V/ VB # )r   r^   )Zdummyr_   )r`   r   rT   r_   s   &*, r   r_   ZThreadPool.Process  s    "%%%r   Nc                s2    \         P                  WW#4       R # r
   )r    r   )r   r   rM   rN   r   r   r   ZThreadPool.__init__  s    d{=r   c                s    \         P                  ! 4       V n        \         P                  ! 4       V n        V P                  P                  V n        V P                  P                  V n        R # r
   )rf   rg   rw   rx   rA   r~   rB   r   r   r   r   re   ZThreadPool._setup_queues  sD    ))+**,--++..,,r   c                s0    V P                   P                  .# r
   )ri   rE   r   r   r   rt   ZThreadPool._get_sentinels  s    %%--..r   c                s    . # r
   rX   )r   r   r   r   Z ThreadPool._get_worker_sentinels  s    	r   c                s      V P                  RR7       K    \        P                   d     Mi ; i\        T4       F  pT P	                  R4       K  	  R# )TF)ZblockN)rB   rf   ZEmptyr   rA   )rK   r   r   rR   r   r   r   ZThreadPool._help_stuff_finish  sH    	%({{ 		tAKK s    //c                s2    \         P                  ! V4       R # r
   )r   r   )r   r   r   r   r   r   r   ZThreadPool._wait_for_updates  s    

7r   )rw   rx   r   r~   )NNrX   )r   r    r!   r"   ry   r   r_   r   re   rt   r   r   r   r#   r$   r%   r'   r   r   r     s]     O& &>-/     r   )NrX   NF))Z__all__r   r   rn   rf   ru   r   r*   r   r   r)   r   r   r   Z
connectionr   r   r   r   r	   Zcountr   r   r   rI   r   r(   r.   r1   rW   rJ   ZdictrY   Zobjectr    r   ZAsyncResultr   r   r   r   rX   r   r   <module>r      s    <
    	        '  	 oo5i 0 0< <"+<Z$ $.v6 vx)8& )8V %" %"V?"6 ?"J	"L 	"$ $r   