+
    Df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   trackingThreadFactory2ThreadPool.__init__.<locals>.trackingThreadFactory`   sH    ''++-13F LL'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    <<<88Or!   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'	%'	 		 	
 ZZ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     zz,,.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     **'')==JJOOG$ 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,     TYY22"T(31T\\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& 6T 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((DHH5r!   c                   V ^8  d   QhRR/# )r   r   r/   r   )r   s   "r   r   r<      s     2 2f 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     	%%dD>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#    GLL%
%
 "%
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     

llFKKM #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'||| <<$(("JJdllTXX56<<$(("JJOODHHt||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    
 	)DLL>*+)DLL>*+'$,,()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 Ir1a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!   