o
    xi-                     @  sz   d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	 d dl
mZ ddlmZ edZdddZdddZdddZdS )    )annotationsN)	Coroutine)AnyCallableTypeVarcast)asyncio_compat   )MailboxHandle_ThandleMailboxHandle[_T]timeoutfloat | Nonedisplay_progress'Callable[[], Coroutine[Any, Any, None]]returnc                C  s   t | g||dd S )zWait for a handle, possibly displaying progress to the user.

    Equivalent to passing a single handle to `wait_all_with_progress`.
    )r   r   r   )wait_all_with_progress)r   r   r    r   X/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/mailbox/wait_with_progress.pywait_with_progress   s   
r   handle_listlist[MailboxHandle[_T]]list[_T]c                  sT   sg S d j }D ]}|j |urtdqt d fdd}||S )	a  Wait for multiple handles, possibly displaying progress to the user.

    Args:
        handle_list: The handles to wait for.
        timeout: A number of seconds after which to raise a TimeoutError,
            or None if this should never timeout.
        display_progress: An asyncio function that displays progress to
            the user. This function runs using the handles' AsyncioManager.

    Returns:
        A list where the Nth item is the Nth handle's result.

    Raises:
        ValueError: If the handles live in different asyncio threads.
        TimeoutError: If the overall timeout expires.
        HandleAbandonedError: If any handle becomes abandoned.
        Exception: Any exception from the display function is propagated.
    r   z'Handles have different AsyncioManagers.r   r   c               	     sz   t   4 I d H % d urt  } |  }nd }t|dI d H W  d   I d H  S 1 I d H s6w   Y  d S N)r   )r   cancel_on_exittime	monotonic_wait_handles_async)elapsed_timeremaining_timeoutr   r   
start_timer   r   r   progress_loop_with_timeoutA   s   

0z:wait_all_with_progress.<locals>.progress_loop_with_timeoutN)r   r   )asyncer
ValueErrorr   r   run)r   r   r   r$   r   r#   r   r!   r   r      s   


r   c             	     s   dd  D d
 fdd}t  4 I d	H }tt D ]	}||| q W d	  I d	H  n1 I d	H s:w   Y  ttt S )zTAsynchronously wait for multiple mailbox handles.

    Just like _wait_handles.
    c                 S  s   g | ]}d qS )Nr   ).0_r   r   r   
<listcomp>Z   s    z'_wait_handles_async.<locals>.<listcomp>indexintr   Nonec                   s$    |  }|j dI d H | < d S r   )
wait_async)r*   r   r   resultsr   r   r   wait_single\   s   z(_wait_handles_async.<locals>.wait_singleN)r*   r+   r   r,   )r   open_task_grouprangelen
start_soonr   listr   )r   r   r0   
task_groupr*   r   r.   r   r   Q   s   	(r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )
__future__r   r   collections.abcr   typingr   r   r   r   wandb.sdk.libr   mailbox_handler
   r   r   r   r   r   r   r   r   <module>   s    

2