o
    ȝid                     @  s   d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	 ddgZ
ejdkr.d dlmZ nd dlmZ e	d	Zejd
krBejZdS ejdkrRddddddZdS ddddddZdddZdS )    )annotationsN)Callable	Coroutine)AnyTypeVarasyncio_runiscoroutinefunction)      )r   _T)r	      )r	      Fdebugloop_factorymainCoroutine[Any, Any, _T]r   boolr   .Callable[[], asyncio.AbstractEventLoop] | Nonereturnc                C  s<   t j||d}|| W  d    S 1 sw   Y  d S )Nr   )asyncioRunnerrun)r   r   r   runner r   K/var/www/html/ocr-read/venv/lib/python3.10/site-packages/uvicorn/_compat.pyr      s   $c                C  sF  z	t   W td ty   Y nw t | std| |d u r(t  }n| }zG|d u r5t | |d ur>|| || W z!t	| ||
  ||  W |d u r`t d  |  S |d u rnt d  |  w z!t	| ||
  ||  W |d u rt d  |  w |d u rt d  |  w )Nz8asyncio.run() cannot be called from a running event loopza coroutine was expected, got )r   get_running_loopRuntimeErroriscoroutine
ValueErrornew_event_loopset_event_loop	set_debugrun_until_complete_cancel_all_tasksshutdown_asyncgensshutdown_default_executorclose)r   r   r   loopr   r   r   r   #   sJ   













r(   asyncio.AbstractEventLoopNonec                 C  st   t | }|s	d S |D ]}|  q| t j|ddi |D ]}| r&q| d ur7| d| |d qd S )Nreturn_exceptionsTz1unhandled exception during asyncio.run() shutdown)message	exceptiontask)r   	all_taskscancelr#   gather	cancelledr-   call_exception_handler)r(   	to_cancelr.   r   r   r   r$   G   s$   

r$   )r   r   r   r   r   r   r   r   )r(   r)   r   r*   )
__future__r   r   syscollections.abcr   r   typingr   r   __all__version_infoinspectr   r   r   r   r$   r   r   r   r   <module>   s(    



$