ó
    F\h>  ã                   óÀ   • S r SSKrSSKrSSKrSSK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KJr   " S	 S
\R                  5      r " S S5      rSSS.S jrS rg))ÚRunnerÚruné    Né   )Ú
coroutines)Úevents)Ú
exceptions)Útasks)Ú	constantsc                   ó    • \ rS rSrSrSrSrSrg)Ú_Stateé   ÚcreatedÚinitializedÚclosed© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚCREATEDÚINITIALIZEDÚCLOSEDÚ__static_attributes__r   ó    Ú&/usr/lib/python3.13/asyncio/runners.pyr   r      s   † Ø€GØ€KØƒFr   r   c                   óZ   • \ rS rSrSrSSS.S jrS rS rS rS	 r	SS
.S jr
S rS rSrg)r   é   aù  A context manager that controls event loop life cycle.

The context manager always creates a new event loop,
allows to run async functions inside it,
and properly finalizes the loop at the context manager exit.

If debug is True, the event loop will be run in debug mode.
If loop_factory is passed, it is used for new event loop creation.

asyncio.run(main(), debug=True)

is a shortcut for

with asyncio.Runner(debug=True) as runner:
    runner.run(main())

The run() method can be called multiple times within the runner's context.

This can be useful for interactive console (e.g. IPython),
unittest runners, console tools, -- everywhere when async code
is called from existing sync framework and where the preferred single
asyncio.run() call doesn't work.

N©ÚdebugÚloop_factoryc                ó~   • [         R                  U l        Xl        X l        S U l        S U l        SU l        SU l        g )Nr   F)	r   r   Ú_stateÚ_debugÚ_loop_factoryÚ_loopÚ_contextÚ_interrupt_countÚ_set_event_loop)Úselfr   r    s      r   Ú__init__ÚRunner.__init__0   s6   € Ü—n‘nˆŒØŒØ)ÔØˆŒ
ØˆŒØ !ˆÔØ$ˆÕr   c                 ó&   • U R                  5         U $ ©N)Ú
_lazy_init©r)   s    r   Ú	__enter__ÚRunner.__enter__9   s   € Ø�‰ÔØˆr   c                 ó$   • U R                  5         g r-   )Úclose)r)   Úexc_typeÚexc_valÚexc_tbs       r   Ú__exit__ÚRunner.__exit__=   s   € Ø�
‰
�r   c                 ó`  • U R                   [        R                  La  g U R                  n[	        U5        UR                  UR                  5       5        UR                  UR                  [        R                  5      5        U R                  (       a  [        R                  " S5        UR                  5         SU l        [        R                  U l         g! U R                  (       a  [        R                  " S5        WR                  5         SU l        [        R                  U l         f = f)zShutdown and close event loop.N)r"   r   r   r%   Ú_cancel_all_tasksÚrun_until_completeÚshutdown_asyncgensÚshutdown_default_executorr
   ÚTHREAD_JOIN_TIMEOUTr(   r   Úset_event_loopr3   r   )r)   Úloops     r   r3   ÚRunner.close@   sÑ   € à�;‰;œf×0Ñ0Ò0Øð	(Ø—:‘:ˆDÜ˜dÔ#Ø×#Ñ# D×$;Ñ$;Ó$=Ô>Ø×#Ñ#Ø×.Ñ.¬y×/LÑ/LÓMôOð ×#×#Ü×%Ò% dÔ+Ø�J‰JŒLØˆDŒJÜ Ÿ-™-ˆD�Køð	 ×#×#Ü×%Ò% dÔ+Ø�J‰JŒLØˆDŒJÜ Ÿ-™-ˆD�Kús    A$C ÃAD-c                 ó:   • U R                  5         U R                  $ )zReturn embedded event loop.)r.   r%   r/   s    r   Úget_loopÚRunner.get_loopQ   s   € à�‰ÔØ�z‰zÐr   ©Úcontextc                óú  • [         R                  " U5      (       d  [        SR                  U5      5      e[        R
                  " 5       b  [        S5      eU R                  5         Uc  U R                  nU R                  R                  XS9n[        R                  " 5       [        R                  " 5       L a{  [        R                  " [        R                   5      [        R"                  L aF  [$        R&                  " U R(                  US9n [        R                  " [        R                   U5        OSnSU l         U R                  R-                  U5      Ub\  [        R                  " [        R                   5      UL a4  [        R                  " [        R                   [        R"                  5        $ $ $ ! [         a    Sn N�f = f! [.        R0                   a7    U R*                  S:”  a%  [3        USS5      nUb  U" 5       S:X  a
  [5        5       ee f = f! Ub\  [        R                  " [        R                   5      UL a4  [        R                  " [        R                   [        R"                  5        f f f = f)z/Run a coroutine inside the embedded event loop.z"a coroutine was expected, got {!r}Nz7Runner.run() cannot be called from a running event looprE   )Ú	main_taskr   Úuncancel)r   ÚiscoroutineÚ
ValueErrorÚformatr   Ú_get_running_loopÚRuntimeErrorr.   r&   r%   Úcreate_taskÚ	threadingÚcurrent_threadÚmain_threadÚsignalÚ	getsignalÚSIGINTÚdefault_int_handlerÚ	functoolsÚpartialÚ
_on_sigintr'   r;   r   ÚCancelledErrorÚgetattrÚKeyboardInterrupt)r)   ÚcororF   ÚtaskÚsigint_handlerrI   s         r   r   Ú
Runner.runV   sð  € ä×%Ò% d×+Ñ+ÜÐA×HÑHÈÓNÓOÐOä×#Ò#Ó%Ñ1äØIóKð Kð 	�‰Ôà‰?Ø—m‘mˆGØ�z‰z×%Ñ% dÐ%Ð<ˆä×$Ò$Ó&¬)×*?Ò*?Ó*AÒAÜ× Ò ¤§¡Ó/´6×3MÑ3MÒMä&×.Ò.¨t¯©È$ÑOˆNð&Ü—’œfŸm™m¨^Õ<ð "ˆNà !ˆÔð	IØ—:‘:×0Ñ0°Ó6ð Ñ*Ü×$Ò$¤V§]¡]Ó3°~ÒEä—’œfŸm™m¬V×-GÑ-GÕHð Fð +øô% ó &ð "&’ð	&ûô ×(Ñ(ó 	Ø×$Ñ$ qÓ(Ü" 4¨°TÓ:�ØÑ'©H«J¸!«OÜ+Ó-Ð-Øð	ûð Ñ*Ü×$Ò$¤V§]¡]Ó3°~ÒEä—’œfŸm™m¬V×-GÑ-GÕHð Fð +ús,   Ä%F9 Ä?G Æ9GÇGÇAHÈH ÈA!I:c                 ó<  • U R                   [        R                  L a  [        S5      eU R                   [        R                  L a  g U R
                  cS  [        R                  " 5       U l        U R                  (       d'  [        R                  " U R                  5        SU l	        OU R                  5       U l        U R                  b%  U R                  R                  U R                  5        [        R                  " 5       U l        [        R                  U l         g )NzRunner is closedT)r"   r   r   rN   r   r$   r   Únew_event_loopr%   r(   r?   r#   Ú	set_debugÚcontextvarsÚcopy_contextr&   r/   s    r   r.   ÚRunner._lazy_initƒ   sÂ   € Ø�;‰;œ&Ÿ-™-Ò'ÜÐ1Ó2Ð2Ø�;‰;œ&×,Ñ,Ò,ØØ×ÑÑ%Ü×.Ò.Ó0ˆDŒJØ×'×'ô ×%Ò% d§j¡jÔ1Ø'+�Ô$øà×+Ñ+Ó-ˆDŒJØ�;‰;Ñ"Ø�J‰J× Ñ  §¡Ô-Ü#×0Ò0Ó2ˆŒÜ×(Ñ(ˆ�r   c                 óä   • U =R                   S-  sl         U R                   S:X  aB  UR                  5       (       d-  UR                  5         U R                  R	                  S 5        g [        5       e)Nr   c                  ó   • g r-   r   r   r   r   Ú<lambda>Ú#Runner._on_sigint.<locals>.<lambda>›   s   € °Dr   )r'   ÚdoneÚcancelr%   Úcall_soon_threadsafer\   )r)   ÚsignumÚframerH   s       r   rY   ÚRunner._on_sigint–   sW   € Ø×Ò Ñ"ÕØ× Ñ  AÓ%¨i¯n©n×.>Ñ.>Ø×ÑÔà�J‰J×+Ñ+©LÔ9ØÜÓ!Ð!r   )r&   r#   r'   r%   r$   r(   r"   )r   r   r   r   Ú__doc__r*   r0   r7   r3   rC   r   r.   rY   r   r   r   r   r   r      s=   † ñð6 !%°4õ %òòò(ò"ð
 $(õ +IòZ)õ&"r   r   r   c                ó®   • [         R                  " 5       b  [        S5      e[        XS9 nUR	                  U 5      sSSS5        $ ! , (       d  f       g= f)au  Execute the coroutine and return the result.

This function runs the passed coroutine, taking care of
managing the asyncio event loop, finalizing asynchronous
generators and closing the default executor.

This function cannot be called when another asyncio event loop is
running in the same thread.

If debug is True, the event loop will be run in debug mode.
If loop_factory is passed, it is used for new event loop creation.

This function always creates a new event loop and closes it at the end.
It should be used as a main entry point for asyncio programs, and should
ideally only be called once.

The executor is given a timeout duration of 5 minutes to shutdown.
If the executor hasn't finished within that duration, a warning is
emitted and the executor is closed.

Example:

    async def main():
        await asyncio.sleep(1)
        print('hello')

    asyncio.run(main())
Nz8asyncio.run() cannot be called from a running event loopr   )r   rM   rN   r   r   )Úmainr   r    Úrunners       r   r   r       sI   € ô: ×ÒÓ!Ñ-äØFóHð 	Hô 
�eÒ	7¸6Ø�z‰z˜$Ó÷ 
8×	7×	7ús   «AÁ
Ac                 óh  • [         R                  " U 5      nU(       d  g U H  nUR                  5         M     U R                  [         R                  " USS065        U HP  nUR                  5       (       a  M  UR                  5       c  M-  U R                  SUR                  5       US.5        MR     g )NÚreturn_exceptionsTz1unhandled exception during asyncio.run() shutdown)ÚmessageÚ	exceptionr^   )r	   Ú	all_tasksrl   r;   ÚgatherÚ	cancelledrx   Úcall_exception_handler)r@   Ú	to_cancelr^   s      r   r:   r:   Æ   s‘   € Ü—’ Ó%€IÞØãˆØ�‰Žñ ð 	×ÑœEŸLšL¨)ÐLÀtÑLÔMãˆØ�>‰>×ÑÙØ�>‰>ÓÓ'Ø×'Ñ'ØNØ!Ÿ^™^Ó-Øñ)ö ò	 r   )Ú__all__rd   ÚenumrW   rP   rS   Ú r   r   r   r	   r
   ÚEnumr   r   r   r:   r   r   r   Ú<module>r‚      sW   ðØ
€ã Û Û Û Û Ý Ý Ý Ý Ý ôˆT�Y‰Yô ÷I"ñ I"ðX ¨$õ # óLr   