o
    ni	                     @   s   d 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mZm	Z	m
Z
mZ erOddlmZ ddlmZ ddlmZ ddlmZmZ ee	e
e eef e	d f ZeeZG d	d
 d
ejZG dd deZdS )zTInternal utility routines.

Collection of classes to support the internal process.

    N)TYPE_CHECKINGOptionalTupleTypeUnion)Queue)Event)TracebackType)RecordResult)NNNc                   @   sV   e Zd ZU dZded< ed ed< dd	d
ZdddZdddZded fddZ	dS )ExceptionThreadz0Class to catch exceptions when running a thread.r   _ExceptionThread__stoppedExceptionType_ExceptionThread__exceptionstoppedreturnNc                 C   s   t j|  || _d | _d S N)	threadingThread__init__r   r   )selfr    r   ^/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/wandb/sdk/internal/internal_util.pyr   $   s   
zExceptionThread.__init__c                 C      t r   NotImplementedErrorr   r   r   r   _run)      zExceptionThread._runc                 C   sl   z'z|    W n ty   t | _Y nw W | jr$| jr&| j  d S d S d S | jr4| jr5| j  w w w r   )r   	Exceptionsysexc_infor   r   setr   r   r   r   run,   s   zExceptionThread.runc                 C   s   | j S r   )r   r   r   r   r   get_exception5   s   zExceptionThread.get_exception)r   r   r   Nr   N)
__name__
__module____qualname____doc____annotations__r   r   r   r#   r$   r   r   r   r   r      s   
 


	r   c                   @   sb   e Zd ZdZ	d								
		dddZdddZdddZdddZdddZdddZ	dS )RecordLoopThreadz+Class to manage reading from queues safely.  input_record_qQueue[Record]result_qQueue[Result]r   r   debounce_interval_msfloatr   Nc                 C   s*   t j| |d || _|| _|| _|| _d S )N)r   )r   r   _input_record_q	_result_q_stopped_debounce_interval_ms)r   r-   r/   r   r1   r   r   r   r   <   s
   
zRecordLoopThread.__init__c                 C   r   r   r   r   r   r   r   _setupI   r   zRecordLoopThread._setuprecordr
   c                 C   r   r   r   )r   r8   r   r   r   _processL   r   zRecordLoopThread._processc                 C   r   r   r   r   r   r   r   _finishO   r   zRecordLoopThread._finishc                 C   r   r   r   r   r   r   r   	_debounceR   r   zRecordLoopThread._debouncec                 C   s   |    t }| j s>t | | jd kr |   t }z	| jjdd}W n
 tj	y3   Y qw | 
| | j r|   d S )Ng     @@   )timeout)r7   timer5   is_setr6   r;   r3   getqueueEmptyr9   r:   )r   startr8   r   r   r   r   U   s   


	zRecordLoopThread._run)r,   )
r-   r.   r/   r0   r   r   r1   r2   r   Nr%   )r8   r
   r   N)
r&   r'   r(   r)   r   r7   r9   r:   r;   r   r   r   r   r   r+   9   s&    




r+   )r)   loggingrA   r    r   r>   typingr   r   r   r   r   r   r   typesr	   wandb.proto.wandb_internal_pb2r
   r   BaseExceptionr   	getLoggerr&   loggerr   r   r+   r   r   r   r   <module>   s(    
