o
    -wi                     @  s   d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZ d
dlmZmZ e	rTddlmZ dddZG dd dZdddZdS )z8Module for starting up the service process (wandb-core).    )annotationsN)TYPE_CHECKING)_sentry)
core_debugdcgm_profiling_enablederror_reporting_enabled)WandbCoreNotAvailableError)ipc_support)get_core_path   )service_port_fileservice_token)Settingssettingsr   returnServiceProcessc              
   C  sN   t jt| dd zt| W S  ty& } zt | W Y d}~dS d}~ww )zWStart the internal service process.

    Returns:
        A handle to the process.
    service)tagsprocess_contextN)r   configure_scopedict_launch_server	Exceptionreraise)r   e r   b/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/lib/service/service_process.pystart   s   
r   c                   @  s2   e Zd ZdZddd	Zedd
dZdddZdS )r   z3A handle to a process running the internal service.connection_tokenservice_token.ServiceTokenprocesssubprocess.Popenr   Nonec                C  s   || _ || _d S )N)_token_process)selfr   r    r   r   r   __init__)   s   
zServiceProcess.__init__c                 C  s   | j S )z&A token for connecting to the process.)r#   r%   r   r   r   token2   s   zServiceProcess.tokenintc                 C  s
   | j  S )z5Wait for the process to end and return its exit code.)r$   waitr'   r   r   r   join7   s   
zServiceProcess.joinN)r   r   r    r!   r   r"   )r   r   )r   r)   )__name__
__module____qualname____doc__r&   propertyr(   r+   r   r   r   r   r   &   s    
	c                 C  sR  t  dkrtj}d}nd}d}tt }t }t	
|d| d}g }zt }W n tyC } zt| W Y d}~nd}~ww ||g t sR|d td	d
r^|ddg t rf|d |dt|g |d|g tjs~|d tj|tjd||d}	tj||	| jd}
t|
|	dW  d   S 1 sw   Y  dS )zLaunch server and set ports.WindowsFr   Tzport-z.txtNz--no-observabilityFalse)defaultz--log-levelz-4z--enable-dcgm-profilingz--port-filenamez--pidz--listen-on-localhost)env	close_fdscreationflagsstart_new_session)timeout)r   r    )platformsystem
subprocessCREATE_NEW_PROCESS_GROUPstrosgetpidtempfileTemporaryDirectorypathlibPathr
   r   r   r   extendr   appendr   r   r	   SUPPORTS_UNIXPopenenvironr   poll_for_tokenx_service_waitr   )r   r6   r7   pidtmpdir	port_fileservice_args	core_pathr   procr(   r   r   r   r   <   sP   






$r   )r   r   r   r   )r/   
__future__r   r>   rB   r9   r;   r@   typingr   wandbr   	wandb.envr   r   r   wandb.errorsr   wandb.sdk.lib.servicer	   
wandb.utilr
    r   r   wandb.sdk.wandb_settingsr   r   r   r   r   r   r   r   <module>   s&    
