ó
    Ö›‘h•  ã                  óÊ   • S r SSKJr  SSKrSSKJrJr  SSKJ	r	  SSK
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 jrS rS rS rS r/ SQrg)zY
Extended thread dispatching support.

For basic support see reactor threading API docs.
é    )ÚannotationsN)ÚCallableÚTypeVar)Ú	ParamSpec)Údefer)ÚIReactorFromThreads)Úfailure)Ú
ThreadPoolÚ_PÚ_Rc                ór   ^ ^• [         R                  " 5       mSUU 4S jjnUR                  " XR/UQ70 UD6  T$ )aó  
Call the function C{f} using a thread from the given threadpool and return
the result as a Deferred.

This function is only used by client code which is maintaining its own
threadpool.  To run a function in the reactor's threadpool, use
C{deferToThread}.

@param reactor: The reactor in whose main thread the Deferred will be
    invoked.

@param threadpool: An object which supports the C{callInThreadWithCallback}
    method of C{twisted.python.threadpool.ThreadPool}.

@param f: The function to call.
@param args: positional arguments to pass to f.
@param kwargs: keyword arguments to pass to f.

@return: A Deferred which fires a callback with the result of f, or an
    errback with a L{twisted.python.failure.Failure} if f throws an
    exception.
c                ó†   >• U (       a  TR                  TR                  U5        g TR                  TR                  U5        g ©N)ÚcallFromThreadÚcallbackÚerrback)ÚsuccessÚresultÚdÚreactors     €€Ú\C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/internet/threads.pyÚonResultÚ#deferToThreadPool.<locals>.onResult9   s.   ø€ ÞØ×"Ñ" 1§:¡:¨vÕ6à×"Ñ" 1§9¡9¨fÕ5ó    )r   Úboolr   z_R | BaseExceptionÚreturnÚNone)r   ÚDeferredÚcallInThreadWithCallback)r   Ú
threadpoolÚfÚargsÚkwargsr   r   s   `     @r   ÚdeferToThreadPoolr$      s:   ù€ ô: "ŸNšNÓ,€A÷6ð 6ð ×'Ò'¨ÐE°dÒE¸fÒEà€Hr   c                óJ   • SSK Jn  [        X3R                  5       U /UQ70 UD6$ )aT  
Run a function in a thread and return the result as a Deferred.

@param f: The function to call.
@param args: positional arguments to pass to f.
@param kwargs: keyword arguments to pass to f.

@return: A Deferred which fires a callback with the result of f,
or an errback with a L{twisted.python.failure.Failure} if f throws
an exception.
r   ©r   )Útwisted.internetr   r$   ÚgetThreadPool)r!   r"   r#   r   s       r   ÚdeferToThreadr)   D   s'   € õ )ä˜W×&;Ñ&;Ó&=¸qÐRÀ4ÒRÈ6ÑRÐRr   c                ó,   • U  H  u  pnU" U0 UD6  M     g)z
Run a list of functions.
N© )Ú	tupleListr!   r"   r#   s       r   Ú_runMultipler-   U   s   € ó %‰ˆ�Ù	ˆ4Ð�6Ôò %r   c                ó<   • SSK Jn  UR                  [        U 5        g)zu
Run a list of functions in the same thread.

tupleList should be a list of (function, argsList, kwargsDict) tuples.
r   r&   N)r'   r   ÚcallInThreadr-   )r,   r   s     r   ÚcallMultipleInThreadr0   ]   s   € õ )à×Ñœ yÕ1r   c                óê   ^^^^• [         R                   " 5       mUUUU4S jnU R                  U5        TR                  5       n[        U[        R
                  5      (       a  UR                  5         U$ )aQ  
Run a function in the reactor from a thread, and wait for the result
synchronously.  If the function returns a L{Deferred}, wait for its
result and return that.

@param reactor: The L{IReactorThreads} provider which will be used to
    schedule the function call.
@param f: the callable to run in the reactor thread
@type f: any callable.
@param a: the arguments to pass to C{f}.
@param kw: the keyword arguments to pass to C{f}.

@return: the result of the L{Deferred} returned by C{f}, or the result
    of C{f} if it returns anything other than a L{Deferred}.

@raise Exception: If C{f} raises a synchronous exception,
    C{blockingCallFromThread} will raise that exception.  If C{f}
    returns a L{Deferred} which fires with a L{Failure},
    C{blockingCallFromThread} will raise that failure's exception (see
    L{Failure.raiseException}).
c                 óp   >• [         R                  " T/TQ70 TD6n U R                  TR                  5        g r   )r   ÚmaybeDeferredÚaddBothÚput)r   Úar!   ÚkwÚqueues    €€€€r   Ú_callFromThreadÚ/blockingCallFromThread.<locals>._callFromThread€   s-   ø€ Ü×$Ò$ QÐ1¨Ò1¨bÑ1ˆØ�‰�u—y‘yÕ!r   )ÚQueuer   ÚgetÚ
isinstancer	   ÚFailureÚraiseException)r   r!   r6   r7   r9   r   r8   s    ```  @r   ÚblockingCallFromThreadr@   h   sW   û€ ô, �KŠK‹M€E÷"ð "ð ×Ñ˜?Ô+Ø�Y‰Y‹[€FÜ�&œ'Ÿ/™/×*Ñ*Ø×ÑÔØ€Mr   )r)   r$   r0   r@   )r   r   r    r
   r!   zCallable[_P, _R]r"   z_P.argsr#   z	_P.kwargsr   zdefer.Deferred[_R])Ú__doc__Ú
__future__r   r8   r;   Útypingr   r   Útyping_extensionsr   r'   r   Útwisted.internet.interfacesr   Útwisted.pythonr	   Útwisted.python.threadpoolr
   r   r   r$   r)   r-   r0   r@   Ú__all__r+   r   r   Ú<module>rI      s‘   ðñõ #ã ß $å 'å "Ý ;Ý "Ý 0áˆtƒ_€ÙˆTƒ]€ð'Ø ð'àð'ð ð'ð ð	'ð
 ð'ð ô'òTSò"ò2ò òF�r   