U
    aúd  ã                   @   sB   d Z ddlmZ ddlmZ ddlmZ ddœdd„Zd	d
„ ZdS ))Úruné   )Ú
coroutines)Úevents)ÚtasksN)Údebugc                C   s–   t  ¡ dk	rtdƒ‚t | ¡s,td | ¡ƒ‚t  ¡ }z*t  |¡ |dk	rR| |¡ | | ¡W ¢S zt
|ƒ | | ¡ ¡ W 5 t  d¡ | 	¡  X X dS )a¥  Execute the coroutine and return the result.

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

    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.

    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.

    Example:

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

        asyncio.run(main())
    Nz8asyncio.run() cannot be called from a running event loopz"a coroutine was expected, got {!r})r   Z_get_running_loopÚRuntimeErrorr   ZiscoroutineÚ
ValueErrorÚformatZnew_event_loopZset_event_loopÚcloseÚ_cancel_all_tasksÚrun_until_completeZshutdown_asyncgensZ	set_debug)Úmainr   Úloop© r   ú%/usr/lib/python3.8/asyncio/runners.pyr      s"    ÿ



r   c                 C   sv   t  | ¡}|sd S |D ]}| ¡  q|  t j|| ddœŽ¡ |D ]0}| ¡ rNq@| ¡ d k	r@|  d| ¡ |dœ¡ q@d S )NT)r   Zreturn_exceptionsz1unhandled exception during asyncio.run() shutdown)ÚmessageÚ	exceptionÚtask)r   Z	all_tasksZcancelr   ZgatherZ	cancelledr   Zcall_exception_handler)r   Z	to_cancelr   r   r   r   r   6   s"    

ÿýr   )Ú__all__Ú r   r   r   r   r   r   r   r   r   Ú<module>   s
   .