HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib/python3.10/site-packages/tornado/__pycache__/concurrent.cpython-310.pyc
o

��hs �@s�dZddlZddlmZddlZddlZddlZddlmZddl	Z	ddl	m
Z
mZmZm
Z
mZe	�d�ZGdd�de�ZejZejefZd	e
d
efdd�ZGd
d�dej�Ze�Zde
de
d
efdd�Ze�Zd*dd�Zddded
dfdd�Zddded
dfdd�Z ddd e
ee!eeeej"fd
dfd!d"�Z#e	j$dd#d$ed#gdfd
dfd%d&��Z%e	j$ddd$edgdfd
dfd'd&��Z%ddd$ed(d
dfd)d&�Z%dS)+a�Utilities for working with ``Future`` objects.

Tornado previously provided its own ``Future`` class, but now uses
`asyncio.Future`. This module contains utility functions for working
with `asyncio.Future` in a way that is backwards-compatible with
Tornado's old ``Future`` implementation.

While this module is an important part of Tornado's internal
implementation, applications rarely need to interact with it
directly.

�N)�futures)�app_log)�Any�Callable�Optional�Tuple�Union�_Tc@seZdZdS)�ReturnValueIgnoredErrorN)�__name__�
__module__�__qualname__�rr�H/usr/local/CyberPanel/lib/python3.10/site-packages/tornado/concurrent.pyr
*sr
�x�returncCs
t|t�S�N)�
isinstance�FUTURES)rrrr�	is_future4s
rc@sheZdZdedefdededdfdd�Zejd	kr(dde	d
e	ddfdd�Z
dSdde	ddfdd�Z
dS)�
DummyExecutor�fn.�args�kwargsr�futures.Future[_T]cOsFt��}z
t|||i|���W|Sty"t|t���Y|Swr)r�Future�"future_set_result_unless_cancelled�	Exception�future_set_exc_info�sys�exc_info)�selfrrr�futurerrr�submit9s��zDummyExecutor.submit)��	TF�wait�cancel_futuresNcC�dSrr)r!r&r'rrr�shutdownE�zDummyExecutor.shutdowncCr(rr)r!r&rrrr)Jr*)TF)T)rrr
rr	rr#r�version_info�boolr)rrrrr8s
���
�

rrrcsddtdtdtff�fdd�}|r�rtd��t|�dkr#||d�St|�dkr0td	t|���|S)
aEDecorator to run a synchronous method asynchronously on an executor.

    Returns a future.

    The executor to be used is determined by the ``executor``
    attributes of ``self``. To use a different attribute name, pass a
    keyword argument to the decorator::

        @run_on_executor(executor='_thread_pool')
        def foo(self):
            pass

    This decorator should not be confused with the similarly-named
    `.IOLoop.run_in_executor`. In general, using ``run_in_executor``
    when *calling* a blocking method is recommended instead of using
    this decorator when *defining* a method. If compatibility with older
    versions of Tornado is required, consider defining an executor
    and using ``executor.submit()`` at the call site.

    .. versionchanged:: 4.2
       Added keyword arguments to use alternative attributes.

    .. versionchanged:: 5.0
       Always uses the current IOLoop instead of ``self.io_loop``.

    .. versionchanged:: 5.1
       Returns a `.Future` compatible with ``await`` instead of a
       `concurrent.futures.Future`.

    .. deprecated:: 5.1

       The ``callback`` argument is deprecated and will be removed in
       6.0. The decorator itself is discouraged in new code but will
       not be removed in 6.0.

    .. versionchanged:: 6.0

       The ``callback`` argument was removed.
    rr.c	s:��dd��t���dtdtdtdtf��fdd��}|S)N�executorr!rrrcs4t�}t|��j�|g|�Ri|��}t||�|Sr)r�getattrr#�chain_future)r!rr�async_future�conc_future�r-rrr�wrappers 
zCrun_on_executor.<locals>.run_on_executor_decorator.<locals>.wrapper)�get�	functools�wrapsrr)rr3�rr2r�run_on_executor_decorator|s"z2run_on_executor.<locals>.run_on_executor_decoratorz*cannot combine positional and keyword args�rzexpected 1 argument, got %d)rr�
ValueError�len)rrr8rr7r�run_on_executorQs+r<�a�
Future[_T]�bcsFd	�fdd�}t|t�rt||�dSddlm}|���||�dS)
ajChain two futures together so that when one completes, so does the other.

    The result (success or failure) of ``a`` will be copied to ``b``, unless
    ``b`` has already been completed or cancelled by the time ``a`` finishes.

    .. versionchanged:: 5.0

       Now accepts both Tornado/asyncio `Future` objects and
       `concurrent.futures.Future`.

    r=r>rNcsd���rdSt|d�r|��durt�|���dS|��}|dur)��|�dS��|���dS)Nr )�done�hasattrr r�	exception�
set_exception�
set_result�result)r=�a_exc�r?rr�copy�szchain_future.<locals>.copyr)�IOLoop)r=r>rN)rr�future_add_done_callback�tornado.iolooprI�current�
add_future)r=r?rHrIrrGrr/�s

r/r"z%Union[futures.Future[_T], Future[_T]]�valuecCs|��s|�|�dSdS)z�Set the given ``value`` as the `Future`'s result, if not cancelled.

    Avoids ``asyncio.InvalidStateError`` when calling ``set_result()`` on
    a cancelled `asyncio.Future`.

    .. versionadded:: 5.0
    N)�	cancelledrD)r"rNrrrr�s
�r�exccCs(|��s|�|�dStjd|d�dS)a�Set the given ``exc`` as the `Future`'s exception.

    If the Future is already canceled, logs the exception instead. If
    this logging is not desired, the caller should explicitly check
    the state of the Future and call ``Future.set_exception`` instead of
    this wrapper.

    Avoids ``asyncio.InvalidStateError`` when calling ``set_exception()`` on
    a cancelled `asyncio.Future`.

    .. versionadded:: 6.0

    z$Exception after Future was cancelled)r N)rOrCr�error)r"rPrrr�%future_set_exception_unless_cancelled�srRr cCs&|ddur
td��t||d�dS)a�Set the given ``exc_info`` as the `Future`'s exception.

    Understands both `asyncio.Future` and the extensions in older
    versions of Tornado to enable better tracebacks on Python 2.

    .. versionadded:: 5.0

    .. versionchanged:: 6.0

       If the future is already cancelled, this function is a no-op.
       (previously ``asyncio.InvalidStateError`` would be raised)

    r9Nz,future_set_exc_info called with no exception)rrR)r"r rrrr�srr�callbackcCr(rr�r"rSrrrrJ��rJcCr(rrrTrrrrJ�rU).NcCs"|��r
||�dS|�|�dS)aLArrange to call ``callback`` when ``future`` is complete.

    ``callback`` is invoked with one argument, the ``future``.

    If ``future`` is already done, ``callback`` is invoked immediately.
    This may differ from the behavior of ``Future.add_done_callback``,
    which makes no such guarantee.

    .. versionadded:: 5.0
    N)r@�add_done_callbackrTrrrrJs
)r=r>r?r>rN)&�__doc__�asyncio�
concurrentrr5r�types�tornado.logr�typingrrrrr�TypeVarr	rr
rrr,r�Executorr�dummy_executorr<�object�
_NO_RESULTr/r�
BaseExceptionrR�type�
TracebackTyper�overloadrJrrrr�<module>s�


@
"��
���
����
����������