AlkantarClanX12

Your IP : 3.140.185.194


Current Path : /opt/alt/python311/lib64/python3.11/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/asyncio/__pycache__/tasks.cpython-311.pyc

�

c��f�����dZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZejd��jZd-d�Zd-d
�Zd�ZGd�dej��ZeZ	ddlZejxZZn#e$rYnwxYwddd�d�Zejj Z ejj!Z!ejj"Z"de"d�d�Z#d�Z$d�Z%d�Z&d�Z'dd�d�Z(ej)d���Z*d-d�Z+dd�d�Z,dd�d�Z-ej)d ���Z.ee._Gd!�d"ej/��Z0d#d$�d%�Z1d&�Z2d'�Z3e
j4��Z5iZ6d(�Z7d)�Z8d*�Z9d+�Z:e7Z;e:Z<e8Z=e9Z>	dd,lm7Z7m:Z:m8Z8m9Z9m5Z5m6Z6e7Z?e:Z@e8ZAe9ZBdS#e$rYdSwxYw).z0Support for tasks, coroutines and the scheduler.)�Task�create_task�FIRST_COMPLETED�FIRST_EXCEPTION�
ALL_COMPLETED�wait�wait_for�as_completed�sleep�gather�shield�
ensure_future�run_coroutine_threadsafe�current_task�	all_tasks�_register_task�_unregister_task�_enter_task�_leave_task�N)�GenericAlias�)�
base_tasks)�
coroutines)�events)�
exceptions)�futures)�
_is_coroutinec�T�|�tj��}tj|��S)z!Return a currently executed task.)r�get_running_loop�_current_tasks�get��loops �4/opt/alt/python311/lib64/python3.11/asyncio/tasks.pyrr#s&���|��&�(�(����d�#�#�#�c�����tj���d}		tt��}n#t$r|dz
}|dkr�YnwxYw�3�fd�|D��S)z'Return a set of all tasks for the loop.NrTri�c�h��h|].}tj|���u�|����,|��/S�)r�	_get_loop�done)�.0�tr#s  �r$�	<setcomp>zall_tasks.<locals>.<setcomp>=sE���>�>�>�!�� ��#�#�t�+�+�A�F�F�H�H�+�
�+�+�+r%)rr�list�
_all_tasks�RuntimeError)r#�i�taskss`  r$rr*s�����|��&�(�(��	
�A��	���$�$�E�
���	�	�	�
��F�A��D�y�y���y�	�����>�>�>�>�u�>�>�>�>s�0�A	�A	c��|�B	|j}||��dS#t$r tjdtd���YdSwxYwdS)Nz~Task.set_name() was added in Python 3.8, the method support will be mandatory for third-party task implementations since 3.13.���
stacklevel)�set_name�AttributeError�warnings�warn�DeprecationWarning)�task�namer7s   r$�_set_task_namer>As�����	��}�H�
�H�T�N�N�N�N�N��
�	8�	8�	8��M�9�)�Q�
8�
8�
8�
8�
8�
8�
8�	8�����s��&A�Ac���eZdZdZdZdddd��fd�
Z�fd�Zee��Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zdd
�d�Zddd�d�Zdd�Zd�Zd�Zd�fd�	Zd�Z�xZS)rz A coroutine wrapped in a Future.TN)r#r=�contextc���t���|���|jr|jd=tj|��sd|_t
d|�����|�dt����|_nt|��|_d|_
d|_d|_||_
|�tj��|_n||_|j�|j|j���t)|��dS)Nr"���Fza coroutine was expected, got zTask-r�r@)�super�__init__�_source_tracebackr�iscoroutine�_log_destroy_pending�	TypeError�_task_name_counter�_name�str�_num_cancels_requested�_must_cancel�_fut_waiter�_coro�contextvars�copy_context�_context�_loop�	call_soon�_Task__stepr)�self�coror#r=r@�	__class__s     �r$rEz
Task.__init__js���
�����d��#�#�#��!�	+��&�r�*��%�d�+�+�	G�).�D�%��E�T�E�E�F�F�F��<�7�!3�!5�!5�7�7�D�J�J��T���D�J�&'��#�!��������
��?�'�4�6�6�D�M�M�#�D�M��
���T�[�$�-��@�@�@��t�����r%c����|jtjkr7|jr0|dd�}|jr
|j|d<|j�|��t�����dS)Nz%Task was destroyed but it is pending!)r<�message�source_traceback)	�_stater�_PENDINGrHrFrT�call_exception_handlerrD�__del__)rWr@rYs  �r$r`zTask.__del__�sy����;�'�*�*�*�t�/H�*��B���G��%�
E�.2�.D��*�+��J�-�-�g�6�6�6�
���������r%c�*�tj|��S�N)r�
_task_repr�rWs r$�__repr__z
Task.__repr__�s���$�T�*�*�*r%c��|jSrb)rPrds r$�get_coroz
Task.get_coro��
���z�r%c��|jSrb)rKrds r$�get_namez
Task.get_name�rhr%c�.�t|��|_dSrb)rLrK)rW�values  r$r7z
Task.set_name�s����Z�Z��
�
�
r%c� �td���)Nz*Task does not support set_result operation�r0)rW�results  r$�
set_resultzTask.set_result�s���G�H�H�Hr%c� �td���)Nz-Task does not support set_exception operationrn)rW�	exceptions  r$�
set_exceptionzTask.set_exception�s���J�K�K�Kr%)�limitc�,�tj||��S)a�Return the list of stack frames for this task's coroutine.

        If the coroutine is not done, this returns the stack where it is
        suspended.  If the coroutine has completed successfully or was
        cancelled, this returns an empty list.  If the coroutine was
        terminated by an exception, this returns the list of traceback
        frames.

        The frames are always ordered from oldest to newest.

        The optional limit gives the maximum number of frames to
        return; by default all available frames are returned.  Its
        meaning differs depending on whether a stack or a traceback is
        returned: the newest frames of a stack are returned, but the
        oldest frames of a traceback are returned.  (This matches the
        behavior of the traceback module.)

        For reasons beyond our control, only one stack frame is
        returned for a suspended coroutine.
        )r�_task_get_stack)rWrts  r$�	get_stackzTask.get_stack�s��*�)�$��6�6�6r%)rt�filec�.�tj|||��S)anPrint the stack or traceback for this task's coroutine.

        This produces output similar to that of the traceback module,
        for the frames retrieved by get_stack().  The limit argument
        is passed to get_stack().  The file argument is an I/O stream
        to which the output is written; by default output is written
        to sys.stderr.
        )r�_task_print_stack)rWrtrxs   r$�print_stackzTask.print_stack�s���+�D�%��>�>�>r%c���d|_|���rdS|xjdz
c_|j�|j�|���rdSd|_||_dS)a�Request that this task cancel itself.

        This arranges for a CancelledError to be thrown into the
        wrapped coroutine on the next cycle through the event loop.
        The coroutine then has a chance to clean up or even deny
        the request using try/except/finally.

        Unlike Future.cancel, this does not guarantee that the
        task will be cancelled: the exception might be caught and
        acted upon, delaying cancellation of the task or preventing
        cancellation completely.  The task may also return a value or
        raise a different exception.

        Immediately after this method is called, Task.cancelled() will
        not return True (unless the task was already cancelled).  A
        task will be marked as cancelled when the wrapped coroutine
        terminates with a CancelledError exception (even if cancel()
        was not called).

        This also increases the task's count of cancellation requests.
        FrN��msgT)�_log_tracebackr*rMrO�cancelrN�_cancel_message)rWr~s  r$r�zTask.cancel�sx��,$����9�9�;�;�	��5��#�#�q�(�#�#���'���&�&�3�&�/�/�
��t� ���"����tr%c��|jS)z�Return the count of the task's cancellation requests.

        This count is incremented when .cancel() is called
        and may be decremented using .uncancel().
        �rMrds r$�
cancellingzTask.cancelling�s
���*�*r%c�F�|jdkr|xjdzc_|jS)z�Decrement the task's count of cancellation requests.

        This should be called by the party that called `cancel()` on the task
        beforehand.

        Returns the remaining number of cancellation requests.
        rrr�rds r$�uncancelz
Task.uncancel�s/���&��*�*��'�'�1�,�'�'��*�*r%c���|���rtjd|�d|�����|jr5t	|tj��s|���}d|_|j}d|_t|j
|��	|�|�d��}n|�|��}t|dd��}|��8tj|��|j
ur?t!d|�d|�d���}|j
�|j||j����n�|r�||ur;t!d	|����}|j
�|j||j����nnd|_|�|j|j���||_|jr'|j�|j�
��rd|_�nt!d|�d|����}|j
�|j||j����n�|�(|j
�|j|j����n�t3j|��r>t!d
|�d|����}|j
�|j||j����nUt!d|����}|j
�|j||j����n#t6$rf}|jr/d|_t9���|j�
��n&t9���|j��Yd}~n�d}~wtj$r1}||_t9�����Yd}~nqd}~wt@tBf$r'}t9���"|���d}~wtF$r+}t9���"|��Yd}~nd}~wwxYwtI|j
|��d}dS#tI|j
|��d}wxYw)Nz_step(): already done: z, F�_asyncio_future_blockingzTask z got Future z attached to a different looprCzTask cannot await on itself: r}z-yield was used instead of yield from in task z with z;yield was used instead of yield from for generator in task zTask got bad yield: )%r*r�InvalidStateErrorrN�
isinstance�CancelledError�_make_cancelled_errorrPrOrrT�send�throw�getattrrr)r0rUrVrSr��add_done_callback�
_Task__wakeupr�r��inspect�isgenerator�
StopIterationrDrprl�_cancelled_exc�KeyboardInterrupt�
SystemExitrs�
BaseExceptionr)rW�excrXro�blocking�new_excrYs      �r$�__stepzTask.__steps�����9�9�;�;�	=��.�;�$�;�;�C�;�;�=�=�
=���	&��c�:�#<�=�=�
3��0�0�2�2�� %�D���z������D�J��%�%�%�H	��{����4��������C����$�v�'A�4�H�H�H��#��$�V�,�,�D�J�>�>�*�C��C�C�!�C�C�C�D�D�G��J�(�(���W�d�m�)�E�E�E�E��E���~�~�".�D�D�D�D�#F�#F���
�,�,� �K��$�-�-�I�I�I�I�;@��7��0�0� �M�4�=�1�B�B�B�+1��(��,�:�#�/�6�6�(,�(<� 7� >� >�:�49�� 1��*�<�#'�<�<�17�<�<�=�=�G��J�(�(���W�d�m�)�E�E�E�E����
�$�$�T�[�$�-�$�H�H�H�H��$�V�,�,�
A�&�B�)-�B�B�7=�B�B�C�C���
�$�$��K��$�-�%�A�A�A�A�'�'H�f�'H�'H�I�I���
�$�$��K��$�-�%�A�A�A�A��{�	.�	.�	.�� �
.�$)��!������4�#7��8�8�8�8����"�"�3�9�-�-�-�����������(�	�	�	�"%�D���G�G�N�N�������������!�:�.�	�	�	��G�G�!�!�#�&�&�&�������	'�	'�	'��G�G�!�!�#�&�&�&�&�&�&�&�&�����	'����d
��
�D�)�)�)��D�D�D��
��
�D�)�)�)��D�K�K�K�Ksb�-K�=HO3�
O�
AL+�&O3�+O�='M)�$O3�)O�="N�
O�,!O�
O3�O�O3�3Pc��	|���|���n,#t$r}|�|��Yd}~nd}~wwxYwd}dSrb)rorVr�)rW�futurer�s   r$�__wakeupz
Task.__wakeup[sr��	��M�M�O�O�O�
�K�K�M�M�M�M���	�	�	��K�K��������������	�������s�+�
A�A�Arb)�__name__�
__module__�__qualname__�__doc__rHrEr`�classmethodr�__class_getitem__rergrjr7rprsrwr{r�r�r�rVr��
__classcell__�rYs@r$rrNs��������+�*�. ��%)��d��������6	�	�	�	�	�$��L�1�1��+�+�+������� � � �I�I�I�L�L�L�"&�7�7�7�7�7�.$(�d�	?�	?�	?�	?�	?�(�(�(�(�T+�+�+�
+�
+�
+�U�U�U�U�U�U�n������r%r)r=r@c��tj��}|�|�|��}n|�||���}t||��|S)z]Schedule the execution of a coroutine object in a spawn task.

    Return a Task object.
    NrC)rrrr>)rXr=r@r#r<s     r$rrxsY��
�"�$�$�D�������%�%�������g��6�6���4������Kr%)�timeout�return_whenc���K�tj|��stj|��r$t	dt|��j�����|std���|tttfvrtd|�����t|��}td�|D����rt	d���tj��}t||||���d{V��S)a}Wait for the Futures or Tasks given by fs to complete.

    The fs iterable must not be empty.

    Coroutines will be wrapped in Tasks.

    Returns two sets of Future: (done, pending).

    Usage:

        done, pending = await asyncio.wait(fs)

    Note: This does not raise TimeoutError! Futures that aren't done
    when the timeout occurs are returned in the second set.
    zexpect a list of futures, not zSet of Tasks/Futures is empty.zInvalid return_when value: c3�>K�|]}tj|��V��dSrb)rrG)r+�fs  r$�	<genexpr>zwait.<locals>.<genexpr>�s-����
1�
1��:�!�!�$�$�
1�
1�
1�
1�
1�
1r%z6Passing coroutines is forbidden, use tasks explicitly.N)r�isfuturerrGrI�typer��
ValueErrorrrr�set�anyrr�_wait)�fsr�r�r#s    r$rr�s����� �����N�z�5�b�9�9�N��L��b���9J�L�L�M�M�M�
�;��9�:�:�:��?�O�]�K�K�K��D�{�D�D�E�E�E�	�R���B�
�
1�
1�b�
1�
1�
1�1�1�R��P�Q�Q�Q��"�$�$�D��r�7�K��6�6�6�6�6�6�6�6�6r%c�\�|���s|�d��dSdSrb)r*rp)�waiter�argss  r$�_release_waiterr��s6���;�;�=�=� ����$������ � r%c��K�tj��}|�|�d{V��S|dkr�t||���}|���r|���St||����d{V��	|���S#tj$r}t
j��|�d}~wwxYw|�	��}|�
|t|��}tj
t|��}t||���}|�|��		|�d{V��n~#tj$rl|���r*|���cY|���S|�|��t||����d{V���wxYw|���r(|���|���S|�|��t||����d{V��	|���|���S#tj$r}t
j��|�d}~wwxYw#|���wxYw)a�Wait for the single Future or coroutine to complete, with timeout.

    Coroutine will be wrapped in Task.

    Returns result of the Future or coroutine.  When a timeout occurs,
    it cancels the task and raises TimeoutError.  To avoid the task
    cancellation, wrap it in shield().

    If the wait is cancelled, the task is also cancelled.

    This function is a coroutine.
    Nrr")rrr
r*ro�_cancel_and_waitrr��TimeoutError�
create_future�
call_laterr��	functools�partialr�r��remove_done_callback)�futr�r#r�r��timeout_handle�cbs       r$rr�s������"�$�$�D����y�y�y�y�y�y���!�|�|��C�d�+�+�+���8�8�:�:�	 ��:�:�<�<���s��.�.�.�.�.�.�.�.�.�.�	5��:�:�<�<����(�	5�	5�	5��)�+�+��4�����	5�����
�
�
!�
!�F��_�_�W�o�v�F�F�N�	�	�?�F�	3�	3�B�
��$�
'�
'�
'�C����"���� �	��L�L�L�L�L�L�L�L���(�		�		�		��x�x�z�z�
��z�z�|�|�#�#�2	�������/�(�(��,�,�,�'�s��6�6�6�6�6�6�6�6�6�6��		�����8�8�:�:�	9��:�:�<�<�	�������
�$�$�R�(�(�(�#�3�T�2�2�2�2�2�2�2�2�2�2�
9��z�z�|�|�	���������,�
9�
9�
9� �-�/�/�S�8�����
9�����	���������sf�7B�B3�B.�.B3�(D1�0I+�17F,�(I+�>.F,�,*I+�+,I+�I�I(�I#�#I(�(I+�+Jc�����	�
K�|s
Jd���|����
d�	|�|�|t�
���	t|������	�
fd�}|D]}|�|���	�
�d{V���	��	���|D]}|�|���n5#�	��	���|D]}|�|���wxYwt��t��}}|D]A}|���r|�	|���,|�	|���B||fS)zVInternal helper for wait().

    The fs argument must be a collection of Futures.
    zSet of Futures is empty.Nc�(���dz��dks>�tks3�tkri|���sW|����E����������s��d��dSdSdSdSdS)Nrr)rr�	cancelledrrr�r*rp)r��counterr�r�r�s ����r$�_on_completionz_wait.<locals>._on_completions�����1����q�L�L��?�*�*��?�*�*�A�K�K�M�M�*�01���
�
�0I��)��%�%�'�'�'��;�;�=�=�
(��!�!�$�'�'�'�'�'�
+�*�*�*�0I�0I�
(�
(r%)
r�r�r��lenr�r�r�r�r*�add)r�r�r�r#r�r�r*�pendingr�r�r�s  `     @@@r$r�r��s���������
�)�)�)�)�)�2�
�
�
�
!�
!�F��N�������/�6�J�J���"�g�g�G�
(�
(�
(�
(�
(�
(�
(�
(��,�,��	���N�+�+�+�+�3����������%��!�!�#�#�#��	3�	3�A�
�"�"�>�2�2�2�2�	3���%��!�!�#�#�#��	3�	3�A�
�"�"�>�2�2�2�2�	3�����E�E�3�5�5�'�D�
�����6�6�8�8�	��H�H�Q�K�K�K�K��K�K��N�N�N�N���=�s�9B2�22C$c��(K�|���}tjt|��}|�|��	|���|�d{V��|�|��dS#|�|��wxYw)z<Cancel the *fut* future or task and wait until it completes.N)r�r�r�r�r�r�r�)r�r#r�r�s    r$r�r�'s������
�
�
!�
!�F�	�	�?�F�	3�	3�B����"����%��
�
������������� � ��$�$�$�$�$��� � ��$�$�$�$���s�A:�:B)r�c#����	�
�K�tj|��stj|��r$t	dt|��j�����ddlm}|���tj
���	�	fd�t|��D���d�
���fd�}��
�fd���fd�}�D]}|������r|��	�
||���
tt�����D]}|��V��dS)	a^Return an iterator whose values are coroutines.

    When waiting for the yielded coroutines you'll get the results (or
    exceptions!) of the original Futures (or coroutines), in the order
    in which and as soon as they complete.

    This differs from PEP 3148; the proper way to use this is:

        for f in as_completed(fs):
            result = await f  # The 'await' may raise.
            # Use result.

    If a timeout is specified, the 'await' will raise
    TimeoutError when the timeout occurs before all Futures are done.

    Note: The futures 'f' are not necessarily members of fs.
    z#expect an iterable of futures, not r)�Queuec�2��h|]}t|������S)r")r
)r+r�r#s  �r$r-zas_completed.<locals>.<setcomp>Qs&���9�9�9�A�M�!�$�'�'�'�9�9�9r%Nc����D],}|������d���-����dSrb)r��
put_nowait�clear)r�r�r*�todos ���r$�_on_timeoutz!as_completed.<locals>._on_timeoutTsL����	"�	"�A�
�"�"�>�2�2�2��O�O�D�!�!�!�!��
�
�����r%c����sdS��|����|���s������dSdSdSrb)�remover�r�)r�r*r�r�s ���r$r�z$as_completed.<locals>._on_completionZsf����	��F����A������������	$��2��!�!�#�#�#�#�#�	$�	$�2�2r%c���K������d{V��}|�tj�|���Srb)r!rr�ro)r�r*s �r$�
_wait_for_onez#as_completed.<locals>._wait_for_onebsB������(�(�*�*���������9��)�)��x�x�z�z�r%)rr�rrGrIr�r��queuesr�r�_get_event_loopr�r�r��ranger�)r�r�r�r�r�r��_r�r*r#r�r�s       @@@@@r$r	r	8s����������$�����S�z�5�b�9�9�S��Q�d�2�h�h�>O�Q�Q�R�R�R��������5�7�7�D��!�#�#�D�9�9�9�9��R���9�9�9�D��N��������$�$�$�$�$�$�$�������,�,��	���N�+�+�+�+��?��#�����+�>�>��
�3�t�9�9�
�
�����m�o�o������r%c#�K�dV�dS)z�Skip one event loop run cycle.

    This is a private helper for 'asyncio.sleep()', used
    when the 'delay' is set to 0.  It uses a bare 'yield'
    expression (which Task.__step knows how to handle)
    instead of creating a Future object.
    Nr(r(r%r$�__sleep0r�qs����
�E�E�E�E�Er%c��>K�|dkrt���d{V��|Stj��}|���}|�|t
j||��}	|�d{V��	|���S#|���wxYw)z9Coroutine that completes after a given time (in seconds).rN)r�rrr�r�r�_set_result_unless_cancelledr�)�delayror#r��hs     r$r
r
}s�������z�z��j�j���������
��"�$�$�D�
�
�
�
!�
!�F������<���	(�	(�A���|�|�|�|�|�|��	���
�
�
�
�����
�
�
�
���s�)B�Br"c�$�t||���S)zmWrap a coroutine or an awaitable in a future.

    If the argument is a Future, it is returned directly.
    r")�_ensure_future)�coro_or_futurer#s  r$r
r
�s��
�.�t�4�4�4�4r%c��tj|��r)|�%|tj|��urtd���|Sd}t	j|��s5t
j|��rt|��}d}ntd���|�tjd���}	|�|��S#t$r|s|����wxYw)NzRThe future belongs to a different loop than the one specified as the loop argumentFTz:An asyncio.Future, a coroutine or an awaitable is required�r5)rr�r)r�rrGr��isawaitable�_wrap_awaitablerIrr�rr0�close)r�r#�called_wrap_awaitables   r$r�r��s�����'�'�����G�,=�n�,M�,M� M� M��E�F�F�
F���!���!�.�1�1�+���~�.�.�	+�,�^�<�<�N�$(�!�!��*�+�+�
+��|��%��3�3�3�������/�/�/������$�	#�� � �"�"�"�
����s�!B6�6"Cc#�:K�|���Ed{V��S)z�Helper for asyncio.ensure_future().

    Wraps awaitable (an object with __await__) into a coroutine
    that will later be wrapped in a Task by ensure_future().
    N)�	__await__)�	awaitables r$r�r��s,����!�*�*�,�,�,�,�,�,�,�,�-r%c�*��eZdZdZ�fd�Zdd�Z�xZS)�_GatheringFuturez�Helper for gather().

    This overrides cancel() to cancel all the children and act more
    like Task.cancel(), which doesn't immediately mark itself as
    cancelled.
    c�p��|�J�t���|���||_d|_dS)Nr"F)rDrE�	_children�_cancel_requested)rW�childrenr#rYs   �r$rEz_GatheringFuture.__init__�s?�������
�����d��#�#�#�!���!&����r%Nc��|���rdSd}|jD]}|�|���rd}�|rd|_|S)NFr}T)r*r�r�r�)rWr~�ret�childs    r$r�z_GatheringFuture.cancel�s`���9�9�;�;�	��5����^�	�	�E��|�|��|�$�$�
�����	*�&*�D�"��
r%rb)r�r�r�r�rEr�r�r�s@r$r�r��sV���������'�'�'�'�'��������r%r�F)�return_exceptionsc������	�
�|s>tj��}|����
�
�g���
S���	�
�fd�}i}g�d�	d�d}d�
|D]u}||vrRt	||���}|�tj|��}||urd|_�	dz
�	|||<|�|��n||}��	|���vt�|����
�
S)a�Return a future aggregating results from the given coroutines/futures.

    Coroutines will be wrapped in a future and scheduled in the event
    loop. They will not necessarily be scheduled in the same order as
    passed in.

    All futures must share the same event loop.  If all the tasks are
    done successfully, the returned future's result is the list of
    results (in the order of the original sequence, not necessarily
    the order of results arrival).  If *return_exceptions* is True,
    exceptions in the tasks are treated the same as successful
    results, and gathered in the result list; otherwise, the first
    raised exception will be immediately propagated to the returned
    future.

    Cancellation: if the outer Future is cancelled, all children (that
    have not completed yet) are also cancelled.  If any child is
    cancelled, this is treated as if it raised CancelledError --
    the outer Future is *not* cancelled in this case.  (This is to
    prevent the cancellation of one child to cause other children to
    be cancelled.)

    If *return_exceptions* is False, cancelling gather() after it
    has been marked done won't cancel any submitted awaitables.
    For instance, gather can be marked done after propagating an
    exception to the caller, therefore, calling ``gather.cancel()``
    after catching an exception (raised by one of the awaitables) from
    gather won't cancel any other awaitables.
    c����dz
�������r*|���s|���dS�sl|���r+|���}��|��dS|���}|���|��dS��kr�g}�D]x}|���r#tj|j�dn|j��}n*|���}|�|���}|�	|���y�j
r+|���}��|��dS��|��dSdS)Nr�)r*r�rrr�rsrr�r�ro�appendr�rp)	r�r��results�resr��	nfinished�nfuts�outerr�s	    �����r$�_done_callbackzgather.<locals>._done_callback�s�����Q��	��=�E�J�J�L�L�=��=�=�?�?�
 ��
�
�����F� �	��}�}���
��/�/�1�1���#�#�C�(�(�(����m�m�o�o���?��'�'��,�,�,��F������G��
$�
$���=�=�?�?�
+�%�3�!�1�9����+�-�-�C�C��-�-�/�/�C��{�!�j�j�l�l�����s�#�#�#�#��&�
*��/�/�1�1���#�#�C�(�(�(�(�(�� � ��)�)�)�)�)�;�r%rNr"Fr)rr�r�rpr�rr)rHr�r�r�)r��coros_or_futuresr#r�
arg_to_fut�argr�r�rrrs`      @@@@r$rr�sK�������<���%�'�'���"�"�$�$��
���������5*�5*�5*�5*�5*�5*�5*�5*�5*�n�J��H�
�E��I��D��E������j� � � ��4�0�0�0�C��|��(��-�-���#�~�~�
,1��(��Q�J�E�!�J�s�O��!�!�.�1�1�1�1��S�/�C����������X�D�1�1�1�E��Lr%c�����t|�������r�Stj���}|�����fd����fd�}�������|���S)a�Wait for a future, shielding it from cancellation.

    The statement

        task = asyncio.create_task(something())
        res = await shield(task)

    is exactly equivalent to the statement

        res = await something()

    *except* that if the coroutine containing it is cancelled, the
    task running in something() is not cancelled.  From the POV of
    something(), the cancellation did not happen.  But its caller is
    still cancelled, so the yield-from expression still raises
    CancelledError.  Note: If something() is cancelled by other means
    this will still cancel shield().

    If you want to completely ignore cancellation (not recommended)
    you can combine shield() with a try/except clause, as follows:

        task = asyncio.create_task(something())
        try:
            res = await shield(task)
        except CancelledError:
            res = None

    Save a reference to tasks passed to this function, to avoid
    a task disappearing mid-execution. The event loop only keeps
    weak references to tasks. A task that isn't referenced elsewhere
    may get garbage collected at any time, even before it's done.
    c�������r*|���s|���dS|���r����dS|���}|���|��dS��|�����dSrb)r�rrr�rsrpro)�innerr�rs  �r$�_inner_done_callbackz$shield.<locals>._inner_done_callback{s�����?�?���	��?�?�$�$�
"����!�!�!��F��?�?���	1��L�L�N�N�N�N�N��/�/�#�#�C����#�#�C�(�(�(�(�(�� � ������0�0�0�0�0r%c�^������s�����dSdSrb)r*r�)rr
r	s ��r$�_outer_done_callbackz$shield.<locals>._outer_done_callback�s8����z�z�|�|�	=��&�&�';�<�<�<�<�<�	=�	=r%)r�r*rr)r�r�)rr#rr
r	rs   @@@r$rrSs������B
�3���E��z�z�|�|������U�#�#�D���� � �E�1�1�1�1�1�"=�=�=�=�=�=�
���0�1�1�1�	���0�1�1�1��Lr%c������tj���std���tj�������fd�}��|���S)zsSubmit a coroutine object to a given event loop.

    Return a concurrent.futures.Future to access the result.
    zA coroutine object is requiredc����	tjt��������dS#ttf$r�t
$r/}����r��|���d}~wwxYw)Nr")r�
_chain_futurer
r�r�r��set_running_or_notify_cancelrs)r�rXr�r#s ���r$�callbackz*run_coroutine_threadsafe.<locals>.callback�s����	��!�-��4�"@�"@�"@�&�I�I�I�I�I���-�.�	�	�	���	�	�	��2�2�4�4�
*��$�$�S�)�)�)������	���s�$)�A3�*A.�.A3)rrGrI�
concurrentr�Future�call_soon_threadsafe)rXr#rr�s`` @r$rr�s{�����
�!�$�'�'�:��8�9�9�9�
�
�
&�
&�
(�
(�F��������	���h�'�'�'��Mr%c�.�tj|��dS)z3Register a new task in asyncio as executed by loop.N)r/r��r<s r$rr�s���N�4�����r%c�r�tj|��}|�td|�d|�d����|t|<dS)NzCannot enter into task z while another task z is being executed.�r r!r0�r#r<rs   r$rr�sf��!�%�d�+�+�L����G�T�G�G�#/�G�G�G�H�H�	H��N�4���r%c�r�tj|��}||urtd|�d|�d����t|=dS)Nz
Leaving task z! does not match the current task �.rrs   r$rr�si��!�%�d�+�+�L��4����A�4�A�A�/;�A�A�A�B�B�	B��t���r%c�.�tj|��dS)zUnregister a task.N)r/�discardrs r$rr�s����t�����r%)rrrrr/r rb)Cr��__all__�concurrent.futuresrrQr�r��	itertools�typesr9�weakrefrr�rrrrrr�count�__next__rJrrr>�	_PyFuturer�_PyTask�_asyncio�_CTask�ImportErrorrrrrrr�rr�r�r	�	coroutiner�r
r
r�r�rr�rrr�WeakSetr/r rrrr�_py_register_task�_py_unregister_task�_py_enter_task�_py_leave_task�_c_register_task�_c_unregister_task�
_c_enter_task�
_c_leave_taskr(r%r$�<module>r4sy��6�6�����������������������������������������������������������������������%�%�%�%�%�%�
%�Y�_�Q�'�'�0��$�$�$�$�>�>�>�>�.
�
�
�[�[�[�[�[�7��[�[�[�|��"��O�O�O�
�M�!�D�6�6��	�	�	�	��D�	����#�D�
�
�
�
�
�$�$�4���$�4���"�0�
�#�
�7�7�7�7�7�@ � � �
D �D �D �N)�)�)�X
%�
%�
%�"!%�6�6�6�6�6�r��
�
���
�����"+/�5�5�5�5�5�,0������2��.�.���.�!.��������w�~����:16�x�x�x�x�x�v?�?�?�D���0�W�_�
�
�
������
 � � �������
#��&������
 �6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�&��)���M��M�M�M��
�	�	�	��D�D�	���s$�B�B�B�E8�8F�F