
    s,g                         d dl Z d dlZd dlZ G d de      Z G d de      Z G d de      Z G d d	      Z G d
 de      Z G d de      Z	y)    Nc                       e Zd ZdZy)BaseTimeoutExceptionzBase exception for timeouts.N__name__
__module____qualname____doc__     e/var/www/trellinator.diamondhoofcare.com/public_html/venv/lib/python3.12/site-packages/rq/timeouts.pyr   r      s    &r   r   c                       e Zd ZdZy)JobTimeoutExceptionz[Raised when a job takes longer to complete than the allowed maximum
    timeout value.
    Nr   r
   r   r   r   r           	r   r   c                       e Zd ZdZy)HorseMonitorTimeoutExceptionz]Raised when waiting for a horse exiting takes longer than the maximum
    timeout value.
    Nr   r
   r   r   r   r      r   r   r   c                   2    e Zd ZdZefdZd Zd Zd Zd Z	y)BaseDeathPenaltyz!Base class to setup job timeouts.c                      || _         || _        y N)_timeout
_exception)selftimeout	exceptionkwargss       r   __init__zBaseDeathPenalty.__init__   s    #r   c                 $    | j                          y r   )setup_death_penaltyr   s    r   	__enter__zBaseDeathPenalty.__enter__#   s      "r   c                 D    	 | j                          y# t        $ r Y yw xY w)NF)cancel_death_penaltyr   )r   typevalue	tracebacks       r   __exit__zBaseDeathPenalty.__exit__&   s3    	%%'  $ 	  	s    	c                     t               r   NotImplementedErrorr   s    r   r   z$BaseDeathPenalty.setup_death_penalty6       !##r   c                     t               r   r(   r   s    r   r"   z%BaseDeathPenalty.cancel_death_penalty9   r*   r   N)
r   r   r   r	   r   r   r    r&   r   r"   r
   r   r   r   r      s!    +*> $# $$r   r   c                       e Zd Zd Zd Zd Zy)UnixSignalDeathPenaltyc                 V    | j                  dj                  | j                              Nz1Task exceeded maximum timeout value ({0} seconds))r   formatr   )r   signumframes      r   handle_death_penaltyz+UnixSignalDeathPenalty.handle_death_penalty>   s$    ooQXXY]YfYfghhr   c                     t        j                   t         j                  | j                         t        j                  | j                         y)zSets up an alarm signal and a signal handler that raises
        an exception after the timeout amount (expressed in seconds).
        N)signalSIGALRMr3   alarmr   r   s    r   r   z*UnixSignalDeathPenalty.setup_death_penaltyA   s,     	fnnd&?&?@T]]#r   c                     t        j                  d       t        j                   t         j                  t         j                         y)zgRemoves the death penalty alarm and puts back the system into
        default signal handling.
        r   N)r5   r7   r6   SIG_DFLr   s    r   r"   z+UnixSignalDeathPenalty.cancel_death_penaltyH   s%     	Qfnnfnn5r   N)r   r   r   r3   r   r"   r
   r   r   r-   r-   =   s    i$6r   r-   c                   :     e Zd Zef fd	Zd Zd Zd Zd Z xZ	S )TimerDeathPenaltyc                     t        |   fi | t        j                         j                  | _        d | _        fd}|| j                  _        y )Nc                 B    t         |   dj                               y r/   )superr   r0   )r   argsr   	__class__r   r   s      r   init_with_messagez5TimerDeathPenalty.__init__.<locals>.init_with_messageX   s    )T+,_,f,fgn,opr   )r>   r   	threadingcurrent_threadident_target_thread_id_timerr   )r   r   r   r   rA   r@   s    ``  r   r   zTimerDeathPenalty.__init__Q   sI    )6v6!*!9!9!;!A!A	q $5 r   c                 V    t        j                  | j                  | j                        S )z7Returns a new timer since timers can only be used once.)rB   Timerr   r3   r   s    r   	new_timerzTimerDeathPenalty.new_timer]   s    t}}d.G.GHHr   c                    t         j                  j                  t        j                  | j                        t        j
                  | j                              }|dk(  r$t        dj                  | j                              |dkD  rHt         j                  j                  t        j                  | j                        d       t        d      y)zRaises an asynchronous exception in another thread.

        Reference http://docs.python.org/c-api/init.html#PyThreadState_SetAsyncExc for more info.
        r   zInvalid thread ID {}   z PyThreadState_SetAsyncExc failedN)
ctypes	pythonapiPyThreadState_SetAsyncExcc_longrE   	py_objectr   
ValueErrorr0   SystemError)r   rets     r   r3   z&TimerDeathPenalty.handle_death_penaltya   s    
 88MM$00163C3CDOO3T
 !83::4;Q;QRSS1W66v}}TE[E[7\^_`@AA r   c                     | j                   dk  ry| j                         | _        | j                  j                          y)zStarts the timer.r   N)r   rI   rF   startr   s    r   r   z%TimerDeathPenalty.setup_death_penaltyo   s/    ==Ann&r   c                 f    | j                   dk  ry| j                  j                          d| _        y)zCancels the timer.r   N)r   rF   cancelr   s    r   r"   z&TimerDeathPenalty.cancel_death_penaltyv   s(    ==Ar   )
r   r   r   r   r   rI   r3   r   r"   __classcell__)r@   s   @r   r;   r;   P   s!    *= 
5IBr   r;   )
rL   r5   rB   	Exceptionr   r   r   r   r-   r;   r
   r   r   <module>rZ      sY      	9 		. 		#7 	$ $B6- 6&+( +r   