Vchcs.dZdZddlZddlZddlmZddlmZddlmZddlm Z dd d ej ej gej fd ej ed ejd ejejej eejej effdZdS)zFSupport for running coroutines in parallel with staggered start times.)staggered_raceN)events) exceptions)locks)tasks)loopcoro_fnsdelayrreturnc s Kptjt| dd g g dtjt jddf  fd  d} | d}|t krtj d{V\}}t|} |D]R}| r<| s(|r|S|t k f D]}|S# D]}|wxYw)aRun 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``. Nprevious_failedr csJK|ctjtj5t j| d{Vdddn #1swxYwY t \}}n#t$rYdSwxYwtj }  |} |t|dzksJ dt |dzksJ |d{V}J||tD]\}}||kr| dS#t t"f$rt$$r$}| |<|Yd}~dSd}~wwxYw)Nir) contextlibZsuppressexceptions_modZ TimeoutErrorrZwait_forwaitZnextZ StopIterationrEvent create_taskappendlen enumeratecancelZ SystemExitZKeyboardInterruptZ BaseExceptionZset)r Z this_indexZcoro_fnZ this_failedZ next_taskZresultZitZer enum_coro_fnsrr run_one_coro running_tasks winner_index winner_results */usr/lib64/python3.11/asyncio/staggered.pyrz$staggered_race..run_one_coroRs`  D$^%@AA D D n_%9%9%;%;UCCCCCCCCC  D D D D D D D D D D D D D D D "&}"5"5 J    FF kmm $$\\+%>%>?? Y'''=!!Z!^3333$:*q.0000 "799______F ' ' '%L"M"-00  1 ?HHJJJ  %-.       %&Jz " OO          s;.AA"%A"*A== B  B E##F">FF"r)rZget_running_looprtypingOptionalrrrrrrrdoneZ cancelledZ exceptionr)rr rZ first_taskZ done_countrZ_Zdrrrrrrrs `` @@@@@@rrrsz  ,6*,,Dh''MMLJM.#_U[9.>B.............`!!,,t"4"455J$$$ C ... ,!J}55555555GD!TJ ,,,Avvxx, ,!++--,kkmm+C ... ,lJ6  A HHJJJJ   A HHJJJJ s B.EE9)Z__doc__Z__all__r rZrrr rrZIterableZCallableZ AwaitablerZfloatZAbstractEventLoopZTupleZAnyZintZListZ Exceptionr)rr sLL  *******. GGG/&/"f6F2F"GHGu%G& G  \ J OC K *+, GGGGGGr