o
    $i$                     @   s   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eZdd Zdd ZG dd	 d	eZG d
d deZdee defddZdee dee fddZG dd dejZdS )    N)Optional)_ERROR_REPORT_TIMEOUTc                 C   s
   t | S N)npisnanvalue r	   S/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/air/_internal/util.pyis_nan   s   
r   c                 C   s   t | pt| S r   )r   r   isinfr   r	   r	   r
   is_nan_or_inf   s   r   c                   @   s   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
   r      s    r   c                       s.   e Zd Zdeddf fddZdd Z  ZS )StartTracebackWithWorkerRankworker_rankreturnNc                    s   t    || _d S r   )super__init__r   )selfr   	__class__r	   r
   r      s   

z%StartTracebackWithWorkerRank.__init__c                 C   s   | j | jffS r   )r   r   )r   r	   r	   r
   
__reduce__"   s   z'StartTracebackWithWorkerRank.__reduce__)r   r   r   intr   r   __classcell__r	   r	   r   r
   r      s    r   excr   c                 C   sb   t ttjdd}|r| S t| trt| jS t		| 
| 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causer	   r	   r
   r'   &   s   


r'   c                 C   s   | sd S t | dd S )Nr!   )r+   )r   r	   r	   r
   exception_causeB   s   r/   c                       s@   e Zd ZdZdd ZdefddZdd Zd fd
d	Z  Z	S )RunnerThreadz(Supervisor thread that runs your script.c                O   s*   t jj| g|R i | || _d | _d S r   )	threadingThreadr   _error_queue_ret)r   error_queueargskwargsr	   r	   r
   r   L   s   
zRunnerThread.__init__ec                 C   s:   z| j j|dtd W d S  tjy   td Y d S 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.)r3   putr   queueFullloggercriticalr   r8   r	   r	   r
   _propagate_exceptionQ   s   
z!RunnerThread._propagate_exceptionc              
   C   s   z| j | ji | j| _W d S  ty   td Y d S  tyF } z|jdkr/td n| 	| W Y d }~d S W Y d }~d S d }~w t
y] } z| 	| W Y d }~d S d }~w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_kwargsr4   StopIterationr>   debug
SystemExitcoderA   BaseExceptionr@   r	   r	   r
   run`   s$   

	
zRunnerThread.runNc                    s   t t| | | jS r   )r   r0   joinr4   )r   r:   r   r	   r
   rK   {   s   zRunnerThread.joinr   )
r   r   r   r   r   rI   rA   rJ   rK   r   r	   r	   r   r
   r0   I   s    r0   )r(   loggingr#   r<   r1   typingr   numpyr   ray.air.constantsr   	getLoggerr   r>   r   r   	Exceptionr   r   r'   r/   r2   r0   r	   r	   r	   r
   <module>   s     
	