
    &`i$                        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Zd dl	m
Z
  ej        e          Zd Zd Z G d de          Z G d d	e          Zd
ee         defdZd
ee         dee         fdZ G d dej                  ZdS )    N)Optional)_ERROR_REPORT_TIMEOUTc                 *    t          j        |           S N)npisnanvalues    j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/air/_internal/util.pyis_nanr      s    8E??    c                 H    t          |           pt          j        |           S r   )r   r   isinfr	   s    r   is_nan_or_infr      s    %==+BHUOO+r   c                       e Zd ZdZdS )StartTracebackzMThese exceptions (and their tracebacks) can be skipped with `skip_exceptions`N)__name__
__module____qualname____doc__ r   r   r   r      s        WWDr   r   c                   .     e Zd Zdeddf fdZd Z xZS )StartTracebackWithWorkerRankworker_rankreturnNc                 V    t                                                       || _        d S r   )super__init__r   )selfr   	__class__s     r   r   z%StartTracebackWithWorkerRank.__init__   s'    &r   c                      | j         | j        ffS r   )r    r   )r   s    r   
__reduce__z'StartTracebackWithWorkerRank.__reduce__"   s    !1 344r   )r   r   r   intr   r"   __classcell__r    s   @r   r   r      sZ        'C 'D ' ' ' ' ' '5 5 5 5 5 5 5r   r   excr   c                 z   t          t          t          j                            dd                              }|r| S t          | t                    rt          | j                  S t          j	        |           
                    | j                  }t          | dd          }|rt          |          |_        |S )a  Skip all contained `StartTracebacks` to reduce traceback output.

    Returns a shallow copy of the exception with all `StartTracebacks` removed.

    If the RAY_AIR_FULL_TRACEBACKS environment variable is set,
    the original exception (not a copy) is returned.
    RAY_AIR_FULL_TRACEBACKS0	__cause__N)boolr#   osenvironget
isinstancer   skip_exceptionsr*   copywith_traceback__traceback__getattr)r&   should_not_shortennew_exccauses       r   r0   r0   &   s     c"*..1JC"P"PQQRR 
#~&& .s}--- inn++C,=>>G Cd++E 3+E22Nr   c                 ,    | sd S t          | dd           S )Nr*   )r4   )r&   s    r   exception_causer9   B   s!     t3T***r   c                   <     e Zd ZdZd ZdefdZd Zd fd	Z xZ	S )	RunnerThreadz(Supervisor thread that runs your script.c                V    t          j        j        | g|R i | || _        d | _        d S r   )	threadingThreadr   _error_queue_ret)r   error_queueargskwargss       r   r   zRunnerThread.__init__L   s9    !$8888888'			r   ec                     	 | j                             |dt                     d S # t          j        $ r t
                              d           Y d S w xY w)NT)blocktimeoutzRunner Thread was unable to report error to main function runner thread. This means a previous error was not processed. This should never happen.)r?   putr   queueFullloggercriticalr   rD   s     r   _propagate_exceptionz!RunnerThread._propagate_exceptionQ   sv    	 !!!49N!OOOOOz 	 	 	OOC     	s   "& )AAc                    	  | j         | j        i | j        | _        d S # t          $ r t
                              d           Y d S t          $ rL}|j        dk    rt
                              d           n| 	                    |           Y d }~d S Y d }~d S d }~wt          $ r }| 	                    |           Y d }~d S d }~ww xY w)NzfThread runner raised StopIteration. Interpreting it as a signal to terminate the thread without error.r   zuThread runner raised SystemExit with error code 0. Interpreting it as a signal to terminate the thread without error.)_target_args_kwargsr@   StopIterationrK   debug
SystemExitcoderN   BaseExceptionrM   s     r   runzRunnerThread.run`   s4   	)$djADLAADIII 	 	 	LLD       	- 	- 	-v{{)    ))!,,,,,,,,,       	) 	) 	)%%a(((((((((	)s'     $C	C;BC$B??CNc                 b    t          t          |                               |           | j        S r   )r   r;   joinr@   )r   rG   r    s     r   rZ   zRunnerThread.join{   s)    lD!!&&w///yr   r   )
r   r   r   r   r   rW   rN   rX   rZ   r$   r%   s   @r   r;   r;   I   s|        22  
m    ) ) )6         r   r;   )r1   loggingr,   rI   r=   typingr   numpyr   ray.air.constantsr   	getLoggerr   rK   r   r   	Exceptionr   r   r0   r9   r>   r;   r   r   r   <module>ra      ss     				                3 3 3 3 3 3		8	$	$  , , ,	 	 	 	 	Y 	 	 	5 5 5 5 5> 5 5 5),     8+), +)1D + + + +4 4 4 4 49# 4 4 4 4 4r   