+
    üÐj  ã                  ó¤   € R t ^ RIHt ^ RIHt ^ RIHtHtHt ^ RI	H
t
 ^RIHt ^RIHt ^RIHt  ! R R	4      t]
! ]4       ! R
 R4      4       tR# )zZ
Implementation of a L{Team} of workers; a thread-pool that can allocate work to
workers.
)Úannotations)Údeque)ÚCallableÚOptionalÚSet)Úimplementer)ÚIWorker)ÚQuit)ÚIExclusiveWorkerc                  ó&   € ] tR t^tRtR R ltRtR# )Ú
Statisticsa«  
Statistics about a L{Team}'s current activity.

@ivar idleWorkerCount: The number of idle workers.
@type idleWorkerCount: L{int}

@ivar busyWorkerCount: The number of busy workers.
@type busyWorkerCount: L{int}

@ivar backloggedWorkCount: The number of work items passed to L{Team.do}
    which have not yet been sent to a worker to be performed because not
    enough workers are available.
@type backloggedWorkCount: L{int}
c               ó(   € V ^8„  d   QhRRRRRRRR/# )é   ÚidleWorkerCountÚintÚbusyWorkerCountÚbackloggedWorkCountÚreturnÚNone© )Úformats   "Ú8/usr/lib/python3/dist-packages/twisted/_threads/_team.pyÚ__annotate__ÚStatistics.__annotate__%   s,   € ÷ 7ñ 7Ø"ð7Ø58ð7ØORð7à	ñ7ó    c                	ó*   € Wn         W n        W0n        R # ©N)r   r   r   )Úselfr   r   r   s   &&&&r   Ú__init__ÚStatistics.__init__%   s   € ð  /ÔØ.ÔØ#6Ö r   )r   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__r   r   r   r   r      s   † ñ÷7ñ 7r   r   c                  óŽ   € ] tR t^-tRtR R ltR R ltR R ltRR	 R
 lltRR R llt	R R lt
R R ltR R ltR R ltRtR# )ÚTeama,  
A composite L{IWorker} implementation.

@ivar _quit: A L{Quit} flag indicating whether this L{Team} has been quit
    yet.  This may be set by an arbitrary thread since L{Team.quit} may be
    called from anywhere.

@ivar _coordinator: the L{IExclusiveWorker} coordinating access to this
    L{Team}'s internal resources.

@ivar _createWorker: a callable that will create new workers.

@ivar _logException: a 0-argument callable called in an exception context
    when there is an unhandled error from a task passed to L{Team.do}

@ivar _idle: a L{set} of idle workers.

@ivar _busyCount: the number of workers currently busy.

@ivar _pending: a C{deque} of tasks - that is, 0-argument callables passed
    to L{Team.do} - that are outstanding.

@ivar _shouldQuitCoordinator: A flag indicating that the coordinator should
    be quit at the next available opportunity.  Unlike L{Team._quit}, this
    flag is only set by the coordinator.

@ivar _toShrink: the number of workers to shrink this L{Team} by at the
    next available opportunity; set in the coordinator.
c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úcoordinatorr
   ÚcreateWorkerzCallable[[], Optional[IWorker]]ÚlogExceptionzCallable[[], None]r   )r   s   "r   r   ÚTeam.__annotate__M   s(   € ÷ ñ à%ðð 6ðð )ñ	r   c                ó®   € \        4       V n        Wn        W n        W0n        \        4       V n        ^ V n        \        4       V n	        RV n
        ^ V n        R# )aH  
@param coordinator: an L{IExclusiveWorker} which will coordinate access
    to resources on this L{Team}; that is to say, an
    L{IExclusiveWorker} whose C{do} method ensures that its given work
    will be executed in a mutually exclusive context, not in parallel
    with other work enqueued by C{do} (although possibly in parallel
    with the caller).

@param createWorker: A 0-argument callable that will create an
    L{IWorker} to perform work.

@param logException: A 0-argument callable called in an exception
    context when the work passed to C{do} raises an exception.
FN)r	   Ú_quitÚ_coordinatorÚ_createWorkerÚ_logExceptionÚsetÚ_idleÚ
_busyCountr   Ú_pendingÚ_shouldQuitCoordinatorÚ	_toShrink)r   r)   r*   r+   s   &&&&r   r   ÚTeam.__init__M   sI   € ô( “VˆŒ
Ø'ÔØ)ÔØ)Ôô $'£5ˆŒ
ØˆŒÜ8=»ˆŒØ&+ˆÔ#ØˆŽr   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r,   m   s   € ÷ Pñ P˜Jñ Pr   c                ó|   € \        \        V P                  4      V P                  \        V P                  4      4      # )zƒ
Gather information on the current status of this L{Team}.

@return: a L{Statistics} describing the current state of this L{Team}.
)r   Úlenr3   r4   r5   ©r   s   &r   Ú
statisticsÚTeam.statisticsm   s(   € ô œ#˜dŸj™j›/¨4¯?©?¼CÀÇÁÓ<NÓOÐOr   c               ó    € V ^8„  d   QhRRRR/# )r   Únr   r   r   r   )r   s   "r   r   r,   u   s   € ÷ ,ñ ,�cð ,˜dñ ,r   c                ó„   a a€ S P                   P                  4        S P                  P                  R VV 3R ll4       pR# )zw
Increase the the number of idle workers by C{n}.

@param n: The number of new idle workers to create.
@type n: L{int}
c               ó   € V ^8„  d   QhRR/# ©r   r   r   r   )r   s   "r   r   ÚTeam.grow.<locals>.__annotate__   s   € ÷ 	,ñ 	, ñ 	,r   c                 ó|   <€ \        S4       F+  p SP                  4       pVf    R # SP                  V4       K-  	  R # r   )Úranger0   Ú_recycleWorker)ÚxÚworkerr@   r   s     €€r   ÚcreateOneWorkerÚ"Team.grow.<locals>.createOneWorker~   s5   ø€ ä˜1–X�Ø×+Ñ+Ó-�Ø’>ÚØ×#Ñ# FÖ+ó	 r   N©r.   Úcheckr/   Údo)r   r@   rJ   s   ff r   ÚgrowÚ	Team.growu   s8   ù€ ð 	�
‰
×ÑÔà	×	Ñ	×	Ñ	÷	,ð 	,ó 
ò	,r   Nc               ó    € V ^8„  d   QhRRRR/# ©r   r@   zOptional[int]r   r   r   )r   s   "r   r   r,   †   s   € ÷ 	:ñ 	:˜ð 	:°ñ 	:r   c                ó~   a a€ S P                   P                  4        S P                  P                  VV 3R l4       R# )z·
Decrease the number of idle workers by C{n}.

@param n: The number of idle workers to shut down, or L{None} (or
    unspecified) to shut down all workers.
@type n: L{int} or L{None}
c                 ó&   <€ SP                  S 4      # r   )Ú_quitIdlers)r@   r   s   €€r   Ú<lambda>ÚTeam.shrink.<locals>.<lambda>�   s   ø€  T×%5Ñ%5°aÔ%8r   NrL   )r   r@   s   ffr   ÚshrinkÚTeam.shrink†   s*   ù€ ð 	�
‰
×ÑÔØ×Ñ×ÑÕ8Ö9r   c               ó    € V ^8„  d   QhRRRR/# rR   r   )r   s   "r   r   r,   ‘   s   € ÷ %ñ %˜]ð %°dñ %r   c                óª  € Vf'   \        V P                  4      V P                  ,           p\        V4       FX  pV P                  '       d+   V P                  P	                  4       P                  4        K?  V ;P                  ^,          un        KZ  	  V P                  '       d0   V P                  ^ 8X  d   V P                  P                  4        R# R# R# )zd
The implmentation of C{shrink}, performed by the coordinator worker.

@param n: see L{Team.shrink}
N)	r;   r3   r4   rF   ÚpopÚquitr7   r6   r/   )r   r@   rH   s   && r   rU   ÚTeam._quitIdlers‘   s�   € ð Š9Ü�D—J‘J“ $§/¡/Õ1ˆAÜ�q–ˆAØ�z�zˆzØ—
‘
—‘Ó ×%Ñ%Ö'à—’ !Õ#—ñ	 ð
 ×&×&Ð&¨4¯?©?¸aÔ+?Ø×Ñ×"Ñ"Ö$ñ ,@Ñ&r   c               ó    € V ^8„  d   QhRRRR/# )r   ÚtaskzCallable[[], object]r   r   r   )r   s   "r   r   r,   ¡   s   € ÷ Eñ EÐ+ð E°ñ Er   c                ó~   a a€ S P                   P                  4        S P                  P                  V V3R l4       R# )z]
Perform some work in a worker created by C{createWorker}.

@param task: the callable to run
c                 ó&   <€ S P                  S4      # r   )Ú_coordinateThisTask©r   r`   s   €€r   rV   ÚTeam.do.<locals>.<lambda>¨   s   ø€  T×%=Ñ%=¸dÔ%Cr   NrL   rd   s   ffr   rN   ÚTeam.do¡   s*   ù€ ð 	�
‰
×ÑÔØ×Ñ×ÑÕCÖDr   c               ó    € V ^8„  d   QhRRRR/# )r   r`   zCallable[..., object]r   r   r   )r   s   "r   r   r,   ª   s   € ÷ 5ñ 5Ð(=ð 5À$ñ 5r   c                ó0  a aa€ S P                   '       d   S P                   P                  4       MS P                  4       pVf   S P                  P	                  S4       R# VoS ;P
                  ^,          un        VP                  R VV V3R ll4       pR# )zÈ
Select a worker to dispatch to, either an idle one or a new one, and
perform it.

This method should run on the coordinator worker.

@param task: the task to dispatch
@type task: 0-argument callable
Nc               ó   € V ^8„  d   QhRR/# rC   r   )r   s   "r   r   Ú.Team._coordinateThisTask.<locals>.__annotate__¾   s   € ÷ 		5ñ 		5˜ñ 		5r   c                 ó    <€  S! 4        SP                  P                  R  VV3R ll4       p R#   \          d    SP                  4         LBi ; i)c               ó   € V ^8„  d   QhRR/# rC   r   )r   s   "r   r   Ú>Team._coordinateThisTask.<locals>.doWork.<locals>.__annotate__Å   s   € ÷ 5ñ 5 Dñ 5r   c                 ó\   <€ S;P                   ^,          un         SP                  S 4       R# )é   N)r4   rG   )Únot_none_workerr   s   €€r   ÚidleAndPendingÚ@Team._coordinateThisTask.<locals>.doWork.<locals>.idleAndPendingÄ   s   ø€ à—’ 1Õ$•Ø×#Ñ# OÖ4r   N)ÚBaseExceptionr1   r/   rN   )rq   rp   r   r`   s    €€€r   ÚdoWorkÚ(Team._coordinateThisTask.<locals>.doWork½   sO   ø€ ð%Ù”ð ×Ñ×!Ñ!÷5ð 5ó "ò5øô	 !ô %Ø×"Ñ"Ö$ð%ús   ƒ/ ¯AÁA)r3   r\   r0   r5   Úappendr4   rN   )r   r`   rI   rt   rp   s   ff  @r   rc   ÚTeam._coordinateThisTaskª   sr   ú€ ð &*§Z§Z Z�—‘—‘Ô!°T×5GÑ5GÓ5IˆØŠ>ð �M‰M× Ñ  Ô&ÙØ ˆØ�Š˜1Õ�à	�‰÷		5ñ 		5ó 
ò		5r   c               ó    € V ^8„  d   QhRRRR/# )r   rI   r   r   r   r   )r   s   "r   r   r,   É   s   € ÷ ñ  Wð °ñ r   c                ó¬  € V P                   P                  V4       V P                  '       d,   V P                  V P                  P	                  4       4       R# V P
                  '       d   V P                  4        R# V P                  ^ 8”  dG   V ;P                  ^,          un        V P                   P                  V4       VP                  4        R# R# )z¨
Called only from coordinator.

Recycle the given worker into the idle pool.

@param worker: a worker created by C{createWorker} and now idle.
@type worker: L{IWorker}
N)
r3   Úaddr5   rc   Úpopleftr6   rU   r7   Úremover]   )r   rI   s   &&r   rG   ÚTeam._recycleWorkerÉ   sŒ   € ð 	�
‰
�‰�vÔØ�=�=ˆ=ð ×$Ñ$ T§]¡]×%:Ñ%:Ó%<Ö=Ø×(×(Ð(Ø×ÑÖØ�^‰^˜aÔØ�NŠN˜aÕ�NØ�J‰J×Ñ˜fÔ%Ø�K‰KŽMñ  r   c               ó   € V ^8„  d   QhRR/# rC   r   )r   s   "r   r   r,   Þ   s   € ÷ 
ñ 
�dñ 
r   c                ó€   a € S P                   P                  4        S P                  P                  R V 3R ll4       pR# )z1
Stop doing work and shut down all idle workers.
c               ó   € V ^8„  d   QhRR/# rC   r   )r   s   "r   r   ÚTeam.quit.<locals>.__annotate__æ   s   € ÷ 	ñ 	 ñ 	r   c                 ó6   <€ R S n         S P                  4        R# )TN)r6   rU   r<   s   €r   ÚstartFinishingÚ!Team.quit.<locals>.startFinishingå   s   ø€ à*.ˆDÔ'Ø×ÑÖr   N)r.   r2   r/   rN   )r   rƒ   s   f r   r]   Ú	Team.quitÞ   s3   ø€ ð 	�
‰
�‰Ôð 
×	Ñ	×	Ñ	÷	ó 
ò	r   )	r4   r/   r0   r3   r1   r5   r.   r6   r7   r   )r    r!   r"   r#   r$   r   r=   rO   rX   rU   rN   rc   rG   r]   r%   r   r   r   r'   r'   -   s<   † ñõ<õ@Põ,÷"	:÷%õ Eõ5õ>÷*
ñ 
r   r'   N)r$   Ú
__future__r   Úcollectionsr   Útypingr   r   r   Úzope.interfacer   Ú r   Ú_conveniencer	   Ú	_ithreadsr
   r   r'   r   r   r   Ú<module>r�      sO   ðñ
õ #å ß *Ñ *å &å Ý Ý '÷7ñ 7ñ0 ˆWÓ÷zð zó òzr   