§
    Ètºf•  ã                  ó¾   — d Z ddlmZ ddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ  e	d
¦  «        Z ed¦  «        Zdd„Zd„ Zd„ Zd„ Zd„ Zg d¢ZdS )zY
Extended thread dispatching support.

For basic support see reactor threading API docs.
é    )ÚannotationsN)ÚCallableÚTypeVar)Ú	ParamSpec)Údefer)ÚIReactorFromThreads)Úfailure)Ú
ThreadPoolÚ_PÚ_RÚreactorr   Ú
threadpoolr
   ÚfúCallable[_P, _R]Úargsú_P.argsÚkwargsú	_P.kwargsÚreturnúdefer.Deferred[_R]c                ób   ‡ ‡— t          j        ¦   «         Šdˆˆ fd„} |j        ||g|¢R i |¤Ž ‰S )	a3  
    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.
    ÚsuccessÚboolÚresultú_R | BaseExceptionr   ÚNonec                ó|   •— | r‰                      ‰j        |¦  «         d S ‰                      ‰j        |¦  «         d S ©N)ÚcallFromThreadÚcallbackÚerrback)r   r   Údr   s     €€úW/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/internet/threads.pyÚonResultz#deferToThreadPool.<locals>.onResult9   sG   ø€ Øð 	6Ø×"Ò" 1¤:¨vÑ6Ô6Ð6Ð6Ð6à×"Ò" 1¤9¨fÑ5Ô5Ð5Ð5Ð5ó    )r   r   r   r   r   r   )r   ÚDeferredÚcallInThreadWithCallback)r   r   r   r   r   r$   r"   s   `     @r#   ÚdeferToThreadPoolr(      sb   øø€ õ: "œNÑ,Ô,€Að6ð 6ð 6ð 6ð 6ð 6ð 6ð (€JÔ'¨°!ÐE°dÐEÐEÐE¸fÐEÐEÐEà€Hr%   c                óV   — ddl m} t          ||                     ¦   «         | g|¢R i |¤ŽS )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   sD   € ð )Ð(Ð(Ð(Ð(Ð(å˜W g×&;Ò&;Ñ&=Ô&=¸qÐRÀ4ÐRÐRÐRÈ6ÐRÐRÐRr%   c                ó(   — | D ]\  }}} ||i |¤Ž ŒdS )z"
    Run a list of functions.
    N© )Ú	tupleListr   r   r   s       r#   Ú_runMultipler1   U   s;   € ð %ð ð ‰ˆˆ4�Ø	ˆˆ4Ð�6ÐÐÐÐðð r%   c                óH   — ddl m} |                     t          | ¦  «         dS )z�
    Run a list of functions in the same thread.

    tupleList should be a list of (function, argsList, kwargsDict) tuples.
    r   r*   N)r+   r   ÚcallInThreadr1   )r0   r   s     r#   ÚcallMultipleInThreadr4   ]   s2   € ð )Ð(Ð(Ð(Ð(Ð(à×Ò� yÑ1Ô1Ð1Ð1Ð1r%   c                óò   ‡‡‡‡— t          j         ¦   «         Šˆˆˆˆfd„}|                      |¦  «         ‰                     ¦   «         }t          |t          j        ¦  «        r|                     ¦   «          |S )a•  
    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                 óf   •— t          j        ‰g‰¢R i ‰¤Ž} |                      ‰j        ¦  «         d S r   )r   ÚmaybeDeferredÚaddBothÚput)r   Úar   ÚkwÚqueues    €€€€r#   Ú_callFromThreadz/blockingCallFromThread.<locals>._callFromThread€   s=   ø€ ÝÔ$ QÐ1¨Ð1Ð1Ð1¨bÐ1Ð1ˆØ�Š�u”yÑ!Ô!Ð!Ð!Ð!r%   )ÚQueuer   ÚgetÚ
isinstancer	   ÚFailureÚraiseException)r   r   r:   r;   r=   r   r<   s    ```  @r#   ÚblockingCallFromThreadrC   h   s‰   øøøø€ õ, ŒK‰MŒM€Eð"ð "ð "ð "ð "ð "ð "ð "ð ×Ò˜?Ñ+Ô+Ð+Ø�YŠY‰[Œ[€FÝ�&�'œ/Ñ*Ô*ð  Ø×ÒÑÔÐØ€Mr%   )r-   r(   r4   rC   )r   r   r   r
   r   r   r   r   r   r   r   r   )Ú__doc__Ú
__future__r   r<   r>   Útypingr   r   Útyping_extensionsr   r+   r   Útwisted.internet.interfacesr   Útwisted.pythonr	   Útwisted.python.threadpoolr
   r   r   r(   r-   r1   r4   rC   Ú__all__r/   r%   r#   ú<module>rL      s%  ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ð $Ð $à 'Ð 'Ð 'Ð 'Ð 'Ð 'à "Ð "Ð "Ð "Ð "Ð "Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø "Ð "Ð "Ð "Ð "Ð "Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0à€Yˆt�_„_€Ø€WˆT�]„]€ð'ð 'ð 'ð 'ðTSð Sð Sð"ð ð ð2ð 2ð 2ð ð  ð  ðFð ð €€€r%   