o
    wi}	                     @  sx   d dl mZ d dl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lmZ d dlmZ dddZG dd dZdS )    )annotationsN)
ApiRequestApiResponse)wandb_settingswandb_setup)ServiceConnection)MailboxHandle
connectionServiceConnection | Noneapi_idstrreturnNonec                 C  sF   | dur!t t | | W d   dS 1 sw   Y  dS dS )z6Clean up the api resources associated with the api id.N)
contextlibsuppress	Exceptionapi_cleanup_request)r	   r    r   Q/home/ubuntu/.local/lib/python3.10/site-packages/wandb/apis/public/service_api.py_cleanup   s
   "r   c                   @  s<   e Zd ZdZdddZddd	Z	
ddddZdddZd
S )
ServiceApizNA lazy initialized handle to the wandb-core service for handling API requests.settingswandb_settings.Settingsc                 C  s   || _ d | _tt | _d S N)	_settings_service_connectionr   uuiduuid4_api_id)selfr   r   r   r   __init__   s   zServiceApi.__init__r   r   c                 C  sL   | j du r#t  | _ | j | j }|j| _t	
| t| j | j | j S )zLConnects to the service and initializes resources for handling API requests.N)r   r   	singletonensure_serviceapi_init_requestr   to_protoidr   weakreffinalizer   )r   responser   r   r   _get_service_connection   s   
z"ServiceApi._get_service_connectionNrequestr   timeoutfloat | Noner   c                 C  s   |   }| j|_|j||dS )zSend an API request to the backend service.

        Creates the backend service connection if it has not been created yet.
        )r+   )r)   r   r%   api_request)r   r*   r+   connr   r   r   send_api_request1   s   	zServiceApi.send_api_requestMailboxHandle[ApiResponse]c                   s"   |   }| j|_||I dH S )zSend an API request to the backend service asynchronously.

        Args:
            request: The Api request to send.
            timeout: The timeout for the request.
        N)r)   r   r%   api_request_async)r   r*   r.   r   r   r   send_api_request_async>   s   
z!ServiceApi.send_api_request_async)r   r   )r   r   r   )r*   r   r+   r,   r   r   )r*   r   r   r0   )__name__
__module____qualname____doc__r    r)   r/   r2   r   r   r   r   r      s    

r   )r	   r
   r   r   r   r   )
__future__r   r   r   r&   wandb.proto.wandb_api_pb2r   r   	wandb.sdkr   r   (wandb.sdk.lib.service.service_connectionr    wandb.sdk.mailbox.mailbox_handler   r   r   r   r   r   r   <module>   s    
