
    ]j                         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	de
e   fdZy)    Nc                       e Zd ZdZy)BaseTimeoutExceptionzBase exception for timeouts.N__name__
__module____qualname____doc__     5/root/env/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                 @    | j                  d| j                   d      Nz%Task exceeded maximum timeout value (z	 seconds))r   r   )r   signumframes      r   handle_death_penaltyz+UnixSignalDeathPenalty.handle_death_penalty>   s     oo Edmm_T]^__r   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SIGALRMr2   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)r4   r6   r5   SIG_DFLr   s    r   r"   z+UnixSignalDeathPenalty.cancel_death_penaltyH   s%     	Qfnnfnn5r   N)r   r   r   r2   r   r"   r
   r   r   r-   r-   =   s    `$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                 ,    t         |   d d       y r/   )superr   )r   argsr   	__class__r   r   s      r   init_with_messagez5TimerDeathPenalty.__init__.<locals>.init_with_messageX   s    )T+.ST[S\\e,fgr   )r=   r   	threadingcurrent_threadident_target_thread_id_timerr   )r   r   r   r   r@   r?   s    ``  r   r   zTimerDeathPenalty.__init__Q   sI    )6v6!*!9!9!;!A!A	h $5 r   c                 V    t        j                  | j                  | j                        S )z7Returns a new timer since timers can only be used once.)rA   Timerr   r2   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                         |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_longrD   	py_objectr   
ValueErrorSystemError)r   rets     r   r2   z&TimerDeathPenalty.handle_death_penaltya   s    
 88MM$00163C3CDOO3T
 !81$2H2H1IJKK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   rH   rE   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   rE   cancelr   s    r   r"   z&TimerDeathPenalty.cancel_death_penaltyv   s(    ==Ar   )
r   r   r   r   r   rH   r2   r   r"   __classcell__)r?   s   @r   r:   r:   P   s!    *= 
5IBr   r:   returnc                  :    t        t        d      rt        S t        S )z>Returns the default death penalty class based on the platform.r5   )hasattrr4   r-   r:   r
   r   r   get_default_death_penalty_classr[   ~   s    vy!%%  r   )rK   r4   rA   	Exceptionr   r   r   r   r-   r:   r#   r[   r
   r   r   <module>r]      sl      	9 		. 		#7 	$ $B6- 6&+( +\!.>)? !r   