+
    üÐj™*  ã                  ó  € R t ^ RIHt ^ RIHtHt ^ RIHtHtH	t	H
t
Ht ^ RIHtHtHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ R	IHt ]! R
4      t]! R4      t ! R R]4      t ! R R]4      t]! 4       t  ! R R4      t!R# )zº
twisted.python.threadpool: a pool of threads to which we dispatch tasks.

In most cases you can just use C{reactor.callInThread} and friends
instead of creating a thread pool directly.
)Úannotations)ÚThreadÚcurrent_thread)ÚAnyÚCallableÚListÚOptionalÚTypeVar)Ú	ParamSpecÚProtocolÚ	TypedDict)Úpool)ÚcontextÚlog)Ú
deprecated)ÚFailure)ÚVersionÚ_PÚ_Rc                  ó"   € ] tR t^tR R ltRtR# )Ú_SupportsQsizec               ó   € V ^8„  d   QhRR/# ©é   ÚreturnÚint© )Úformats   "Ú;/usr/lib/python3/dist-packages/twisted/python/threadpool.pyÚ__annotate__Ú_SupportsQsize.__annotate__   s   € ÷ ñ �sñ ó    c                	ó   € R # ©Nr   ©Úselfs   &r   ÚqsizeÚ_SupportsQsize.qsize   s   € Ùr!   r   N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r&   Ú__static_attributes__r   r!   r   r   r      s   † ÷ñ r!   r   c                  ó,   € ] tR t^"t$ R]R&   R]R&   RtR# )Ú_Stater   ÚminÚmaxr   N)r)   r*   r+   r,   Ú__annotations__r-   r   r!   r   r/   r/   "   s   ‡ Ø	ƒHØ	‡Hr!   r/   c            
      ót  € ] tR t^*tRt^t^tRtRtRt	]
t]! ]! ]! R^^^ 4      RR7      ! ]4      4      t]! ]4      tR(R R llt]R	 R
 l4       t]R R l4       t]R R l4       t]R R l4       t]tR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R  lt R! R" lt!R)R# R$ llt"R% R& lt#R't$R# )*Ú
ThreadPoolaÀ  
This class (hopefully) generalizes the functionality of a pool of threads
to which work can be dispatched.

L{callInThread} and L{stop} should only be called from a single thread.

@ivar started: Whether or not the thread pool is currently running.
@type started: L{bool}

@ivar threads: List of workers currently running in this thread pool.
@type threads: L{list}

@ivar _pool: A hook for testing.
@type _pool: callable compatible with L{_pool}
FNÚTwistedzthreading.current_thread)ÚversionÚreplacementc               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú
minthreadsr   Ú
maxthreadsÚnamezOptional[str]r   )r   s   "r   r   ÚThreadPool.__annotate__J   s)   € ÷ "Eñ "EØð"EØ/2ð"EØ?Lñ"Er!   c                óÆ   a € V^ 8¼  g   Q R4       hW8:  g   Q R4       hVS n         VS n        VS n        . S n        R V 3R llpR V 3R llpS P	                  WT4      S n        R# )a#  
Create a new threadpool.

@param minthreads: minimum number of threads in the pool
@type minthreads: L{int}

@param maxthreads: maximum number of threads in the pool
@type maxthreads: L{int}

@param name: The name to give this threadpool; visible in log messages.
@type name: native L{str}
úminimum is negativeúminimum is greater than maximumc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úar   Úkwr   r   r   )r   s   "r   r   Ú)ThreadPool.__init__.<locals>.__annotate__`   s!   € ÷ 	ñ 	 cð 	°ð 	¸ñ 	r!   c                 ó‚   <€ SP                   ! V R SP                  4       /VB pSP                  P                  V4       V# )r;   )ÚthreadFactoryÚ_generateNameÚthreadsÚappend)rA   rB   Úthreadr%   s   *, €r   ÚtrackingThreadFactoryÚ2ThreadPool.__init__.<locals>.trackingThreadFactory`   sH   ø€ Ø×'Ò'ØðØ×+Ñ+Ó-ðØ13ñˆFð �L‰L×Ñ Ô'ØˆMr!   c               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   rC   g   s   € ÷ 	ñ 	˜cñ 	r!   c                 óD   <€ S P                   '       g   ^ # S P                  # )é    )Ústartedr1   r$   s   €r   ÚcurrentLimitÚ)ThreadPool.__init__.<locals>.currentLimitg   s   ø€ Ø—<—<�<ÙØ—8‘8ˆOr!   N)r0   r1   r;   rG   Ú_poolÚ_team)r%   r9   r:   r;   rJ   rP   s   f&&&  r   Ú__init__ÚThreadPool.__init__J   sk   ø€ ð ˜QŒÐ5Ð 5Ó5ˆØÔ'ÐJÐ)JÓJÐ'ØˆŒØˆŒØˆŒ	Ø%'ˆŒ÷	ð 	÷	ð 	ð
 —Z‘Z ÓDˆŽ
r!   c               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r<   o   s   € ÷ 	=ñ 	=˜ñ 	=r!   c                óp   € V P                   P                  4       pVP                  VP                  ,           # )zÙ
For legacy compatibility purposes, return a total number of workers.

@return: the current number of workers, both idle and busy (but not
    those that have been quit by L{ThreadPool.adjustPoolsize})
@rtype: L{int}
)rS   Ú
statisticsÚidleWorkerCountÚbusyWorkerCount)r%   Ústatss   & r   ÚworkersÚThreadPool.workersn   s-   € ð —
‘
×%Ñ%Ó'ˆØ×$Ñ$ u×'<Ñ'<Õ<Ð<r!   c               ó   € V ^8„  d   QhRR/# ©r   r   z
list[None]r   )r   s   "r   r   r<   {   s   € ÷ @ñ @˜ñ @r!   c                óZ   € R.V P                   P                  4       P                  ,          # )zÕ
For legacy compatibility purposes, return the number of busy workers as
expressed by a list the length of that number.

@return: the number of workers currently processing a work item.
@rtype: L{list} of L{None}
N)rS   rX   rZ   r$   s   &r   ÚworkingÚThreadPool.workingz   s$   € ð ˆv˜Ÿ
™
×-Ñ-Ó/×?Ñ?Õ?Ð?r!   c               ó   € V ^8„  d   QhRR/# r_   r   )r   s   "r   r   r<   †   s   € ÷ 	@ñ 	@˜ñ 	@r!   c                óZ   € R.V P                   P                  4       P                  ,          # )zü
For legacy compatibility purposes, return the number of idle workers as
expressed by a list the length of that number.

@return: the number of workers currently alive (with an allocated
    thread) but waiting for new work.
@rtype: L{list} of L{None}
N)rS   rX   rY   r$   s   &r   ÚwaitersÚThreadPool.waiters…   s$   € ð ˆv˜Ÿ
™
×-Ñ-Ó/×?Ñ?Õ?Ð?r!   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r<   ’   s   € ÷ ñ ˜ñ r!   c                ó,   a €  ! V 3R lR4      pV! 4       # )z¹
For legacy compatibility purposes, return an object with a C{qsize}
method that indicates the amount of work not yet allocated to a worker.

@return: an object with a C{qsize} method.
c                  ó*   <€ ] tR t^štR V 3R lltRtR# )Ú$ThreadPool._queue.<locals>.NotAQueuec               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   Ú1ThreadPool._queue.<locals>.NotAQueue.__annotate__›   s   € ÷ 	Cñ 	C˜Cñ 	Cr!   c                óL   <€ SP                   P                  4       P                  # )zµ
Pretend to be a Python threading Queue and return the
number of as-yet-unconsumed tasks.

@return: the amount of backlogged work not yet dispatched to a
    worker.
@rtype: L{int}
)rS   rX   ÚbackloggedWorkCount)Úqr%   s   &€r   r&   Ú*ThreadPool._queue.<locals>.NotAQueue.qsize›   s   ø€ ð —z‘z×,Ñ,Ó.×BÑBÐBr!   r   Nr(   r$   s   €r   Ú	NotAQueuerj   š   s   ø† ÷	Cô 	Cr!   rq   r   )r%   rq   s   f r   Ú_queueÚThreadPool._queue‘   s   ø€ ÷
	Cô 
	Cñ ‹{Ðr!   c               ó   € V ^8„  d   QhRR/# ©r   r   ÚNoner   )r   s   "r   r   r<   «   s   € ÷ 
%ñ 
%�tñ 
%r!   c                óÔ   € RV n         RV n        V P                  4        V P                  P	                  4       P
                  pV'       d   V P                  P                  V4       R# R# )z
Start the threadpool.
FTN)ÚjoinedrO   ÚadjustPoolsizerS   rX   rn   Úgrow)r%   Úbacklogs   & r   ÚstartÚThreadPool.start«   sN   € ð ˆŒØˆŒà×ÑÔØ—*‘*×'Ñ'Ó)×=Ñ=ˆßØ�J‰J�O‰O˜GÖ$ñ r!   c               ó   € V ^8„  d   QhRR/# ru   r   )r   s   "r   r   r<   ·   s   € ÷ ñ ˜dñ r!   c                ó<   € V P                   P                  ^4       R# )zt
Increase the number of available workers for the thread pool by 1, up
to the maximum allowed by L{ThreadPool.max}.
N)rS   rz   r$   s   &r   ÚstartAWorkerÚThreadPool.startAWorker·   s   € ð
 	�
‰
�‰˜Ör!   c               ó   € V ^8„  d   QhRR/# )r   r   Ústrr   )r   s   "r   r   r<   ¾   s   € ÷ Dñ D˜sñ Dr!   c                ó`   € RV P                   ;'       g    \        V 4       RV P                   2# )zk
Generate a name for a new pool thread.

@return: A distinctive name for the thread.
@rtype: native L{str}
zPoolThread-Ú-)r;   Úidr\   r$   s   &r   rF   ÚThreadPool._generateName¾   s,   € ð ˜TŸY™Y×2Ð2¬"¨T«(Ð3°1°T·\±\°NÐCÐCr!   c               ó   € V ^8„  d   QhRR/# ru   r   )r   s   "r   r   r<   Ç   s   € ÷ ñ ˜Tñ r!   c                ó<   € V P                   P                  ^4       R# )zV
Decrease the number of available workers by 1, by quitting one as soon
as it's idle.
N)rS   Úshrinkr$   s   &r   ÚstopAWorkerÚThreadPool.stopAWorkerÇ   s   € ð
 	�
‰
×Ñ˜!Ör!   c               ó    € V ^8„  d   QhRRRR/# )r   Ústater/   r   rv   r   )r   s   "r   r   r<   Î   s   € ÷ 6ñ 6 &ð 6¨Tñ 6r!   c                	ót   € \        V R V4       \        P                  W P                  V P                  4       R# )Ú__dict__N)Úsetattrr4   rT   r0   r1   )r%   rŽ   s   &&r   Ú__setstate__ÚThreadPool.__setstate__Î   s&   € Ü��j %Ô(Ü×Ñ˜D§(¡(¨D¯H©HÖ5r!   c               ó   € V ^8„  d   QhRR/# )r   r   r/   r   )r   s   "r   r   r<   Ò   s   € ÷ 2ñ 2˜fñ 2r!   c                	óD   € \        V P                  V P                  R 7      # ))r0   r1   )r/   r0   r1   r$   s   &r   Ú__getstate__ÚThreadPool.__getstate__Ò   s   € Ü˜$Ÿ(™(¨¯©Ô1Ð1r!   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   ÚfunczCallable[_P, object]Úargsú_P.argsrB   ú	_P.kwargsr   rv   r   )r   s   "r   r   r<   Õ   s,   € ÷ ?ñ ?Ø(ð?Ø18ð?Ø@Ið?à	ñ?r!   c                ó4   € V P                   ! RV.VO5/ VB  R# )zØ
Call a callable object in a separate thread.

@param func: callable object to be called in separate thread

@param args: positional arguments to be passed to C{func}

@param kw: keyword args to be passed to C{func}
N)ÚcallInThreadWithCallback)r%   r™   rš   rB   s   &&*,r   ÚcallInThreadÚThreadPool.callInThreadÕ   s   € ð 	×%Ò% d¨DÐ>°4Ò>¸2Ô>r!   c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   ÚonResultz&Optional[Callable[[bool, _R], object]]r™   zCallable[_P, _R]rš   r›   rB   rœ   r   rv   r   )r   s   "r   r   r<   ã   s<   € ÷ ?!ñ ?!à8ð?!ð ð?!ð ð	?!ð
 ð?!ð 
ñ?!r!   c                ó  aaaaa€ V P                   '       d   R# \        P                  P                  4       P                  R,          oR V3R lloVVVV3R lSn        VSn        V P                  P                  S4       R# )a|  
Call a callable object in a separate thread and call C{onResult} with
the return value, or a L{twisted.python.failure.Failure} if the
callable raises an exception.

The callable is allowed to block, but the C{onResult} function must not
block and should perform as little work as possible.

A typical action for C{onResult} for a threadpool used with a Twisted
reactor would be to schedule a L{twisted.internet.defer.Deferred} to
fire in the main reactor thread using C{.callFromThread}.  Note that
C{onResult} is called inside the separate thread, not inside the
reactor thread.

@param onResult: a callable with the signature C{(success, result)}.
    If the callable returns normally, C{onResult} is called with
    C{(True, result)} where C{result} is the return value of the
    callable.  If the callable throws an exception, C{onResult} is
    called with C{(False, failure)}.

    Optionally, C{onResult} may be L{None}, in which case it is not
    called at all.

@param func: callable object to be called in separate thread

@param args: positional arguments to be passed to C{func}

@param kw: keyword arguments to be passed to C{func}
Nc               ó   € V ^8„  d   QhRR/# ru   r   )r   s   "r   r   Ú9ThreadPool.callInThreadWithCallback.<locals>.__annotate__  s   € ÷ 	 ñ 	 ˜4ñ 	 r!   c                 ó  <€  SP                  4       p R pRSn         SP                  e   SP                  W4       RSn        R# V'       g   \        P
                  ! V 4       R# R#   \         d    \        4       p Rp Lji ; i)TFN)ÚtheWorkÚBaseExceptionr   r¢   r   Úerr)ÚresultÚokÚ	inContexts     €r   r¬   Ú6ThreadPool.callInThreadWithCallback.<locals>.inContext  sw   ø€ ðØ"×*Ñ*Ó,�Ø�ð
 !%ˆIÔØ×!Ñ!Ò-Ø×"Ñ" 2Ô.Ø%)�	Ö"ßÜ—’˜–ñ øô !ô Ü ›�Ø’ðús   ƒA& Á&B Á?B c                 ó:   <€ \         P                  ! SS.S O5/ SB # r#   )r   Úcall)rš   Úctxr™   rB   s   €€€€r   Ú<lambda>Ú5ThreadPool.callInThreadWithCallback.<locals>.<lambda>  s#   ø€ ¤G§L¢LØ�ð%
Øò%
Ø "ò%
r!   éÿÿÿÿ)	rx   r   ÚtheContextTrackerÚcurrentContextÚcontextsr§   r¢   rS   Údo)r%   r¢   r™   rš   rB   r°   r¬   s   &&fjl@@r   rž   Ú#ThreadPool.callInThreadWithCallbackã   s_   ü€ ðH �;�;ˆ;ÙÜ×'Ñ'×6Ñ6Ó8×AÑAÀ"ÕEˆ÷	 ð 	 ÷$
ˆ	Ôð &ˆ	Ôà�
‰
�‰�iÖ r!   c               ó   € V ^8„  d   QhRR/# ru   r   )r   s   "r   r   r<   $  s   € ÷ ñ �dñ r!   c                óœ   € RV n         RV n        V P                  P                  4        V P                   F  pVP                  4        K  	  R# )z)
Shutdown the threads in the threadpool.
TFN)rx   rO   rS   ÚquitrG   Újoin)r%   rI   s   & r   ÚstopÚThreadPool.stop$  s7   € ð ˆŒØˆŒØ�
‰
�‰ÔØ—l”lˆFØ�K‰KŽMó #r!   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r9   zOptional[int]r:   r   rv   r   )r   s   "r   r   r<   .  s$   € ÷ 5ñ 5Ø'ð5Ø<Ið5à	ñ5r!   c                ó  € Vf   V P                   pVf   V P                  pV^ 8¼  g   Q R4       hW8:  g   Q R4       hWn         W n        V P                  '       g   R# V P                  V P                  8”  d7   V P                  P                  V P                  V P                  ,
          4       V P                  V P                   8  d9   V P                  P                  V P                   V P                  ,
          4       R# R# )zÆ
Adjust the number of available threads by setting C{min} and C{max} to
new values.

@param minthreads: The new value for L{ThreadPool.min}.

@param maxthreads: The new value for L{ThreadPool.max}.
Nr>   r?   )r0   r1   rO   r\   rS   rŠ   rz   )r%   r9   r:   s   &&&r   ry   ÚThreadPool.adjustPoolsize.  s¿   € ð ÒØŸ™ˆJØÒØŸ™ˆJà˜QŒÐ5Ð 5Ó5ˆØÔ'ÐJÐ)JÓJÐ'àŒØŒØ�|�|ˆ|Ùð �<‰<˜$Ÿ(™(Ô"Ø�J‰J×Ñ˜dŸl™l¨T¯X©XÕ5Ô6à�<‰<˜$Ÿ(™(Ô"Ø�J‰J�O‰O˜DŸH™H t§|¡|Õ3Ö4ñ #r!   c               ó   € V ^8„  d   QhRR/# ru   r   )r   s   "r   r   r<   M  s   € ÷ *ñ *˜4ñ *r!   c                óØ   € \         P                  ! RV P                   24       \         P                  ! RV P                   24       \         P                  ! RV P                   24       R# )z_
Dump some plain-text informational messages to the log about the state
of this L{ThreadPool}.
z	waiters: z	workers: ztotal: N)r   Úmsgre   ra   rG   r$   s   &r   Ú	dumpStatsÚThreadPool.dumpStatsM  sI   € ô
 	�Š�)˜DŸL™L˜>Ð*Ô+Ü�Š�)˜DŸL™L˜>Ð*Ô+Ü�Š�'˜$Ÿ,™,˜Ð(Ö)r!   )rS   rx   r1   r0   r;   rO   rG   )é   é   N)NN)%r)   r*   r+   r,   Ú__doc__r0   r1   rx   rO   r;   r   rE   Ústaticmethodr   r   r   ÚcurrentThreadrR   rT   Úpropertyr\   ra   re   rr   ro   r|   r€   rF   r‹   r’   r–   rŸ   rž   r½   ry   rÅ   r-   r   r!   r   r4   r4   *   s   † ñð  €CØ
€CØ€FØ€GØ€Dà€MÙ ÙÙ˜I r¨1¨aÓ0Ø2õ	
ð ó	ó€Mñ ˜Ó€E÷"EðH ô	=ó ð	=ð ô@ó ð@ð ô	@ó ð	@ð ôó ðð, 	€Aõ
%õõDõõ6õ2õ?õ?!õB÷5÷>*ñ *r!   r4   N)"rÉ   Ú
__future__r   Ú	threadingr   r   Útypingr   r   r   r   r	   r
   r   r   Útwisted._threadsr   rR   Útwisted.pythonr   r   Útwisted.python.deprecater   Útwisted.python.failurer   Útwisted.python.versionsr   r   r   r   r/   ÚobjectÚ
WorkerStopr4   r   r!   r   Ú<module>r×      sl   ðñ
õ #ç ,ß 9Õ 9ç 1Ñ 1å *ß 'Ý /Ý *Ý +áˆtƒ_€ÙˆTƒ]€ô�Xô ô
ˆYô ñ
 ‹X€
÷j*ó j*r!   