ó
    Ö›‘h¤*  ã                  ó  • S r SSKJr  SSKJrJr  SSKJrJrJ	r	J
r
Jr  SSKJrJrJr  SSKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  \" S5      r\" S5      r " S S\5      r " S S\5      r\ " 5       r! " S S5      r"g)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                  ó   • \ rS rSrSS jrSrg)Ú_SupportsQsizeé   c                ó   • g ©N© ©Úselfs    Ú]C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/python/threadpool.pyÚqsizeÚ_SupportsQsize.qsize   s   € Øó    r   N©ÚreturnÚint©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   Ú__static_attributes__r   r!   r   r   r      s   † ÷r!   r   c                  ó*   • \ rS rSr% S\S'   S\S'   Srg)Ú_Stateé"   r$   ÚminÚmaxr   N)r&   r'   r(   r)   Ú__annotations__r*   r   r!   r   r,   r,   "   s   ‡ Ø	ƒHØ	†Hr!   r,   c            
      óˆ  • \ rS rSrSrSrSrSrSrSr	\
r\" \" \" SSS	S
5      SS9" \5      5      r\" \5      r S     SS jjr\S S j5       r\S!S j5       r\S!S j5       r\S"S j5       r\rS#S jrS#S jrS$S jrS#S jrS%S jrS&S jr        S'S jr          S(S jr S#S jr! S)     S*S jjr"S#S jr#Sr$g)+Ú
ThreadPoolé*   aÀ  
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ÚTwistedé   é   r   zthreading.current_thread)ÚversionÚreplacementc                ó¼   ^ • US:¼  d   S5       eX::  d   S5       eUT l         UT l        UT l        / T l        SU 4S jjnSU 4S jjnT R	                  XT5      T l        g)	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}
r   úminimum is negativeúminimum is greater than maximumc                 ó‚   >• TR                   " U STR                  5       0UD6nTR                  R                  U5        U$ )NÚname)ÚthreadFactoryÚ_generateNameÚthreadsÚappend)ÚaÚkwÚthreadr   s      €r   ÚtrackingThreadFactoryÚ2ThreadPool.__init__.<locals>.trackingThreadFactory`   sH   ø€ Ø×'Ò'ØðØ×+Ñ+Ó-ðØ13ñˆFð �L‰L×Ñ Ô'ØˆMr!   c                 ó@   >• T R                   (       d  gT R                  $ )Nr   )Ústartedr/   r   s   €r   ÚcurrentLimitÚ)ThreadPool.__init__.<locals>.currentLimitg   s   ø€ Ø—<—<ØØ—8‘8ˆOr!   N)rD   r   rE   r   r#   r   r"   )r.   r/   r?   rB   Ú_poolÚ_team)r   Ú
minthreadsÚ
maxthreadsr?   rG   rK   s   `     r   Ú__init__ÚThreadPool.__init__J   sa   ø€ ð ˜Q‹Ð5Ð 5Ó5ˆØÓ'ÐJÐ)JÓJÐ'ØˆŒØˆŒØˆŒ	Ø%'ˆŒ÷	÷	ð
 —Z‘Z ÓDˆ�
r!   c                óh   • U R                   R                  5       nUR                  UR                  -   $ )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}
)rN   Ú
statisticsÚidleWorkerCountÚbusyWorkerCount)r   Ústatss     r   ÚworkersÚThreadPool.workersn   s-   € ð —
‘
×%Ñ%Ó'ˆØ×$Ñ$ u×'<Ñ'<Ñ<Ð<r!   c                óR   • S/U R                   R                  5       R                  -  $ )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)rN   rT   rV   r   s    r   ÚworkingÚThreadPool.workingz   s$   € ð ˆv˜Ÿ
™
×-Ñ-Ó/×?Ñ?Ñ?Ð?r!   c                óR   • S/U R                   R                  5       R                  -  $ )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)rN   rT   rU   r   s    r   ÚwaitersÚThreadPool.waiters…   s$   € ð ˆv˜Ÿ
™
×-Ñ-Ó/×?Ñ?Ñ?Ð?r!   c                ó,   ^ •  " U 4S jS5      nU" 5       $ )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                  ó&   >• \ rS rSrSU 4S jjrSrg)Ú$ThreadPool._queue.<locals>.NotAQueueéš   c                óL   >• TR                   R                  5       R                  $ )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}
)rN   rT   ÚbackloggedWorkCount)Úqr   s    €r   r   Ú*ThreadPool._queue.<locals>.NotAQueue.qsize›   s   ø€ ð —z‘z×,Ñ,Ó.×BÑBÐBr!   r   Nr"   r%   r   s   €r   Ú	NotAQueuerb   š   s   ø† ÷	Cò 	Cr!   rh   r   )r   rh   s   ` r   Ú_queueÚThreadPool._queue‘   s   ø€ ÷
	Cô 
	Cñ ‹{Ðr!   c                óÎ   • SU l         SU l        U R                  5         U R                  R	                  5       R
                  nU(       a  U R                  R                  U5        gg)z
Start the threadpool.
FTN)ÚjoinedrJ   ÚadjustPoolsizerN   rT   re   Úgrow)r   Úbacklogs     r   ÚstartÚThreadPool.start«   sN   € ð ˆŒØˆŒà×ÑÔØ—*‘*×'Ñ'Ó)×=Ñ=ˆÞØ�J‰J�O‰O˜GÕ$ð r!   c                ó:   • U R                   R                  S5        g)zt
Increase the number of available workers for the thread pool by 1, up
to the maximum allowed by L{ThreadPool.max}.
r8   N)rN   rn   r   s    r   ÚstartAWorkerÚThreadPool.startAWorker·   s   € ð
 	�
‰
�‰˜Õr!   c                ó^   • SU R                   =(       d    [        U 5       SU R                   3$ )zk
Generate a name for a new pool thread.

@return: A distinctive name for the thread.
@rtype: native L{str}
zPoolThread-Ú-)r?   ÚidrX   r   s    r   rA   ÚThreadPool._generateName¾   s)   € ð ˜TŸY™Y×2¬"¨T«(Ð3°1°T·\±\°NÐCÐCr!   c                ó:   • U R                   R                  S5        g)zV
Decrease the number of available workers by 1, by quitting one as soon
as it's idle.
r8   N)rN   Úshrinkr   s    r   ÚstopAWorkerÚThreadPool.stopAWorkerÇ   s   € ð
 	�
‰
×Ñ˜!Õr!   c                ór   • [        U SU5        [        R                  X R                  U R                  5        g )NÚ__dict__)Úsetattrr2   rQ   r.   r/   )r   Ústates     r   Ú__setstate__ÚThreadPool.__setstate__Î   s&   € Ü��j %Ô(Ü×Ñ˜D§(¡(¨D¯H©HÕ5r!   c                ó>   • [        U R                  U R                  S9$ )N)r.   r/   )r,   r.   r/   r   s    r   Ú__getstate__ÚThreadPool.__getstate__Ò   s   € Ü˜$Ÿ(™(¨¯©Ñ1Ð1r!   c                ó2   • U R                   " SU/UQ70 UD6  g)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   ÚfuncÚargsrE   s       r   ÚcallInThreadÚThreadPool.callInThreadÕ   s   € ð 	×%Ò% d¨DÐ>°4Ò>¸2Ó>r!   c                óø   ^^^^^• U R                   (       a  g[        R                  R                  5       R                  S   mSU4S jjmUUUU4S jTl        UTl        U R                  R                  T5        g)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}
Néÿÿÿÿc                 óú   >•  TR                  5       n SnS Tl         TR                  b  TR                  X5        S Tl        g U(       d  [        R
                  " U 5        g g ! [         a    [        5       n Sn Ndf = f)NTF)ÚtheWorkÚBaseExceptionr   ÚonResultr   Úerr)ÚresultÚokÚ	inContexts     €r   r•   Ú6ThreadPool.callInThreadWithCallback.<locals>.inContext  sw   ø€ ðØ"×*Ñ*Ó,�Ø�ð
 !%ˆIÔØ×!Ñ!Ñ-Ø×"Ñ" 2Ô.Ø%)�	Õ"ÞÜ—’˜•ð øô !ó Ü ›�Ø’ðús   ƒA! Á!A:Á9A:c                 ó:   >• [         R                  " TT/T Q70 TD6$ r   )r   Úcall)r‰   Úctxrˆ   rE   s   €€€€r   Ú<lambda>Ú5ThreadPool.callInThreadWithCallback.<locals>.<lambda>  s#   ø€ ¤G§L¢LØ�ð%
Øò%
Ø "ò%
r!   ©r#   ÚNone)	rl   r   ÚtheContextTrackerÚcurrentContextÚcontextsr�   r‘   rN   Údo)r   r‘   rˆ   r‰   rE   r™   r•   s     ```@@r   r‡   Ú#ThreadPool.callInThreadWithCallbackã   sX   ü€ ðH �;�;ØÜ×'Ñ'×6Ñ6Ó8×AÑAÀ"ÑEˆ÷	 ÷$
ˆ	Ôð &ˆ	Ôà�
‰
�‰�iÕ r!   c                óš   • SU l         SU l        U R                  R                  5         U R                   H  nUR                  5         M     g)z)
Shutdown the threads in the threadpool.
TFN)rl   rJ   rN   ÚquitrB   Újoin)r   rF   s     r   ÚstopÚThreadPool.stop$  s7   € ð ˆŒØˆŒØ�
‰
�‰ÔØ—l”lˆFØ�K‰KŽMò #r!   c                óà  • Uc  U R                   nUc  U R                  nUS:¼  d   S5       eX::  d   S5       eXl         X l        U R                  (       d  gU R                  U R                  :”  a2  U R                  R                  U R                  U R                  -
  5        U R                  U R                   :  a3  U R                  R                  U R                   U R                  -
  5        gg)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<   r=   )r.   r/   rJ   rX   rN   rz   rn   )r   rO   rP   s      r   rm   Ú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                óÖ   • [         R                  " SU R                   35        [         R                  " SU R                   35        [         R                  " SU R                   35        g)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   Úmsgr^   r[   rB   r   s    r   Ú	dumpStatsÚThreadPool.dumpStatsM  sI   € ô
 	�Š�)˜DŸL™L˜>Ð*Ô+Ü�Š�)˜DŸL™L˜>Ð*Ô+Ü�Š�'˜$Ÿ,™,˜Ð(Õ)r!   )rN   rl   r/   r.   r?   rJ   rB   )r4   r5   N)rO   r$   rP   r$   r?   zOptional[str]r"   )r#   z
list[None])r#   r   rœ   )r#   Ústr)r€   r,   r#   r�   )r#   r,   )rˆ   zCallable[_P, object]r‰   ú_P.argsrE   ú	_P.kwargsr#   r�   )
r‘   z&Optional[Callable[[bool, _R], object]]rˆ   zCallable[_P, _R]r‰   r¯   rE   r°   r#   r�   )NN)rO   úOptional[int]rP   r±   r#   r�   )%r&   r'   r(   r)   Ú__doc__r.   r/   rl   rJ   r?   r   r@   Ústaticmethodr   r   r   ÚcurrentThreadrM   rQ   ÚpropertyrX   r[   r^   ri   rf   rp   rs   rA   r{   r�   r„   rŠ   r‡   r¦   rm   r¬   r*   r   r!   r   r2   r2   *   sŒ  † ñð  €CØ
€CØ€FØ€GØ€Dà€MÙ ÙÙ˜I r¨1¨aÓ0Ø2ò	
ð ó	ó€Mñ ˜Ó€Eð PTð"EØð"EØ/2ð"EØ?Lõ"EðH ó	=ó ð	=ð ó@ó ð@ð ó	@ó ð	@ð óó ðð, 	€Aô
%ôôDôô6ô2ð?Ø(ð?Ø18ð?Ø@Ið?à	ô?ð?!à8ð?!ð ð?!ð ð	?!ð
 ð?!ð 
ô?!ôBð MQð5Ø'ð5Ø<Ið5à	õ5÷>*r!   r2   N)#r²   Ú
__future__r   Ú	threadingr   r   Útypingr   r   r   r	   r
   Útyping_extensionsr   r   r   Útwisted._threadsr   rM   Útwisted.pythonr   r   Útwisted.python.deprecater   Útwisted.python.failurer   Útwisted.python.versionsr   r   r   r   r,   ÚobjectÚ
WorkerStopr2   r   r!   r   Ú<module>rÁ      sl   ðñ
õ #ç ,ß 9Õ 9ç <Ñ <å *ß 'Ý /Ý *Ý +áˆtƒ_€ÙˆTƒ]€ô�Xô ô
ˆYô ñ
 ‹X€
÷j*ò j*r!   