ó
    F\h¥  ã                   óR   • S r SrSSKrSSKJr  SSKJr  SSKJr  SSKJr  SS	.S
 jr	g)zFSupport for running coroutines in parallel with staggered start times.)Ústaggered_raceé    Né   )Úevents)Ú
exceptions)Úlocks)Útasks)Úloopc          
   ƒ   óÊ  ^^^^	^
^^^^^^#   • T=(       d    [         R                  " 5       m[        U 5      mSmSm/ m/ m	[        5       mSm
U
UU4S jmSUUU	UUUUUU4	S jjmSn [        R
                  " 5       nTR                  T" US5      5      nTR                  U5        UR                  T5        UR                  5         SnT(       a&  TR                  5       m
 T
I Sh  v•N   Sm
T(       a  M&  T(       a  [        ST5      eUb  UeTTT	4@	A@$  N/! [        R                   a.  nUnT H  nUR                  " UR                  6   M      SnANjSnAff = f! @	A@f = f7f)ai  Run coroutines with staggered start times and take the first to finish.

This method takes an iterable of coroutine functions. The first one is
started immediately. From then on, whenever the immediately preceding one
fails (raises an exception), or when *delay* seconds has passed, the next
coroutine is started. This continues until one of the coroutines complete
successfully, in which case all others are cancelled, or until all
coroutines fail.

The coroutines provided should be well-behaved in the following way:

* They should only ``return`` if completed successfully.

* They should always raise an exception if they did not complete
  successfully. In particular, if they handle cancellation, they should
  probably reraise, like this::

    try:
        # do work
    except asyncio.CancelledError:
        # undo partially completed work
        raise

Args:
    coro_fns: an iterable of coroutine functions, i.e. callables that
        return a coroutine object when called. Use ``functools.partial`` or
        lambdas to pass arguments.

    delay: amount of time, in seconds, between starting coroutines. If
        ``None``, the coroutines will run sequentially.

    loop: the event loop to use.

Returns:
    tuple *(winner_result, winner_index, exceptions)* where

    - *winner_result*: the result of the winning coroutine, or ``None``
      if no coroutines won.

    - *winner_index*: the index of the winning coroutine in
      ``coro_fns``, or ``None`` if no coroutines won. If the winning
      coroutine may return None on success, *winner_index* can be used
      to definitively determine whether any coroutine won.

    - *exceptions*: list of exceptions returned by the coroutines.
      ``len(exceptions)`` is equal to the number of coroutines actually
      started, and the order is the same as in ``coro_fns``. The winning
      coroutine's entry is ``None``.

Nc                 óþ   >• TR                  U 5        Tb-  TR                  5       (       d  T(       d  TR                  S 5        U R                  5       (       a  g U R	                  5       nUc  g TR                  U5        g )N)ÚdiscardÚdoneÚ
set_resultÚ	cancelledÚ	exceptionÚappend)ÚtaskÚexcÚon_completed_futÚrunning_tasksÚunhandled_exceptionss     €€€Ú(/usr/lib/python3.13/asyncio/staggered.pyÚ	task_doneÚ!staggered_race.<locals>.task_doneJ   si   ø€ Ø×Ñ˜dÔ#àÑ(Ø$×)Ñ)×+Ñ+Þ!à×'Ñ'¨Ô-à�>‰>×ÑØà�n‰nÓˆØ‰;ØØ×#Ñ# CÕ(ó    c              “   ó¬  >	#   • U R                  5       I S h  v•N   UbZ  [        R                  " [        R                  5         [
        R                  " UR                  5       T5      I S h  v•N   S S S 5         [        T5      u  p#[        R                  " 5       n[        R                  " 5       nTR                  T" XT5      5      nTR                  U5        UR                  T5        UR                  5         TR                  S 5        [!        T5      US-   :X  d   e U" 5       I S h  v•N nTb   eUmUm[
        R"                  " T5      nT H  n	X˜Ld  M	  U	R%                  5         M     g  GNW GN! , (       d  f       GN
= f! [         a     g f = f Nk! [&        [(        4 a    e [*         a  n
U
TU'   UR                  5          S n
A
g S n
A
ff = f7f)Nr   )ÚwaitÚ
contextlibÚsuppressÚexceptions_modÚTimeoutErrorr   Úwait_forÚnextÚStopIterationr   ÚEventÚcreate_taskÚaddÚadd_done_callbackÚsetr   ÚlenÚcurrent_taskÚcancelÚ
SystemExitÚKeyboardInterruptÚBaseException)Úok_to_startÚprevious_failedÚ
this_indexÚcoro_fnÚthis_failedÚnext_ok_to_startÚ	next_taskÚresultr*   ÚtÚeÚdelayÚenum_coro_fnsr   r	   Úrun_one_coror   r   Úwinner_indexÚwinner_results              €€€€€€€€€r   r;   Ú$staggered_race.<locals>.run_one_coro[   sž  øé € ð ×ÑÓ × Ð àÑ&Ü×$Ò$¤^×%@Ñ%@ÕAô
 —n’n _×%9Ñ%9Ó%;¸UÓC×CÐC÷ Bð	Ü"& }Ó"5ÑˆJô —k’k“mˆÜ Ÿ;š;›=ÐØ×$Ñ$¡\Ð2BÓ%PÓQˆ	Ø×Ñ˜)Ô$Ø×#Ñ# IÔ.ð 	×ÑÔà×Ñ˜$ÔÜ�:‹ *¨q¡.Ó0Ð0Ð0ð	Ù"›9—_ˆFð  Ñ'Ð'Ð'Ø%ˆLØ"ˆMô !×-Ò-¨dÓ3ˆLÛ"�ØÔ(Ø—H‘H–Jò #òa 	!ò D÷ BÖAûô ó 	Ùð	úñ  %øÜÔ-Ð.ó 	ØÜó 	Ø%&ˆJ�zÑ"Ø�O‰O×Ñûð	üs    ƒG—E.˜+GÁ)E4Á,E1Á-E4Á1GÁ:F ÂBGÄ 
F Ä*FÄ+F Ä/&GÅGÅ1E4Å4
FÅ>GÆ
FÆGÆFÆGÆF ÆGÆ2GÇGÇGÇGzstaggered race failed)ÚreturnN)r   Úget_running_loopÚ	enumerater(   r   r$   r%   r&   r'   Úcreate_futurer   ÚCancelledErrorr+   ÚargsÚExceptionGroup)Úcoro_fnsr9   r	   Úpropagate_cancellation_errorr/   Ú
first_taskÚexr   r:   r   r   r;   r   r   r   r<   r=   s    ``     @@@@@@@@@r   r   r      s_  ÿúé € ðh ×,”6×*Ò*Ó,€DÜ˜hÓ'€MØ€MØ€LØÐØ€JÜ“E€MØÐ÷)÷"6÷ 6ðp $(Ð ðKÜ—k’k“mˆØ×%Ñ%¡l°;ÀÓ&EÓFˆ
Ø×Ñ˜*Ô%Ø×$Ñ$ YÔ/à�‰ÔØ'+Ð$æØ#×1Ñ1Ó3Ðð*Ø&×&Ð&ð
  $Ð÷ ˆmö .ô !Ð!8Ð:NÓOÐOØ'Ñ3Ø.Ð.Ø˜l¨JÐ6àÐ4Ñ6Jñ 'øÜ!×0Ñ0ó *Ø/1Ð,Û)�DØ—K’K §¡Ó)ö *ûð*ûð Ð4Ñ6Jüsa   �AE#Á&A8E ÃD Ã$DÃ%D Ã)	E Ã4E ÄE#ÄD ÄEÄ*$EÅE ÅEÅE ÅE Å E#)
Ú__doc__Ú__all__r   Ú r   r   r   r   r   r   © r   r   Ú<module>rN      s(   ðÙ Là
€ã å Ý *Ý Ý ð 37ö aKr   