HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/twisted/internet/__pycache__/threads.cpython-312.pyc
�

�b���N�dZddlZddlmZddlmZd�Zd�Zd�Z	d�Z
d	�Zgd
�Zy)zY
Extended thread dispatching support.

For basic support see reactor threading API docs.
�N)�defer)�failurec�l���tj����fd�}|j||g|��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.
    c�|��|r�j�j|�y�j�j|�y�N)�callFromThread�callback�errback)�success�result�d�reactors  ���:/usr/lib/python3/dist-packages/twisted/internet/threads.py�onResultz#deferToThreadPool.<locals>.onResult*s.�����"�"�1�:�:�v�6��"�"�1�9�9�f�5�)r�Deferred�callInThreadWithCallback)r�
threadpool�f�args�kwargsrr
s`     @r�deferToThreadPoolrs9���.	����A�6�(�J�'�'��!�E�d�E�f�E��Hrc�L�ddlm}t||j�|g|��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.internetrr�
getThreadPool)rrrrs    r�
deferToThreadr5s)��)��W�g�&;�&;�&=�q�R�4�R�6�R�Rrc�*�|D]\}}}||i|���y)z"
    Run a list of functions.
    N�)�	tupleListrrrs    r�_runMultipler!Fs!��%���4��	�4��6��%rc�<�ddlm}|jt|�y)z�
    Run a list of functions in the same thread.

    tupleList should be a list of (function, argsList, kwargsDict) tuples.
    rrN)rr�callInThreadr!)r rs  r�callMultipleInThreadr$Ns��)�����y�1rc�������tj������fd�}|j|��j�}t|tj
�r|j
�|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�n��tj�g���i���}|j�j�yr)r�
maybeDeferred�addBoth�put)r�ar�kw�queues ����r�_callFromThreadz/blockingCallFromThread.<locals>._callFromThreadqs-����$�$�Q�1��1�b�1�����u�y�y�!r)�Queuer�get�
isinstancer�Failure�raiseException)rrr*r+r-rr,s ```  @r�blockingCallFromThreadr3YsO���,
�K�K�M�E�"����?�+�
�Y�Y�[�F��&�'�/�/�*������Mr)rrr$r3)
�__doc__r,r.rr�twisted.pythonrrrr!r$r3�__all__rrr�<module>r7s8����"�"�!
�HS�"�2� �F�r