
    \j                     H    d dl mZ d dlmZmZ d dlZd dlmZ  G d d      Zy)    )log)EventThreadN)Callablec                   6    e Zd ZdZdededefdZd Zd Zd Z	y	)
RepeatingTaskzf
    A generic mechanism for calling a callback repeatedly at fixed intervals on a worker thread.
    intervalinitial_delaycallablec                     || _         || _        || _        t               | _        t        | j                        | _        d| j                  _        y)a9  
        Creates the task, but does not start the worker thread yet.
        
        :param interval: maximum time in seconds between invocations of the callback
        :param initial_delay: time in seconds to wait before the first invocation
        :param callable: the function to execute repeatedly
        )targetTN)	_RepeatingTask__interval_RepeatingTask__initial_delay_RepeatingTask__actionr   _RepeatingTask__stopr   _run_RepeatingTask__threaddaemon)selfr	   r
   r   s       F/root/env/lib/python3.12/site-packages/ldclient/impl/repeating_task.py__init__zRepeatingTask.__init__   s?     #, gdii0#    c                 8    | j                   j                          y)z+
        Starts the worker thread.
        N)r   startr   s    r   r   zRepeatingTask.start   s     	r   c                 8    | j                   j                          y)zU
        Tells the worker thread to stop. It cannot be restarted after this.
        N)r   setr   s    r   stopzRepeatingTask.stop    s     	r   c                    | j                   dkD  r&| j                  j                  | j                         ry | j                  j                         }|st	        j                         | j
                  z   }	 | j                          |t	        j                         z
  }|dkD  r| j                  j                  |      n| j                  j                         }|sy y # t        $ r"}t        j                  d|z         Y d }~|d }~ww xY w)Nr   z)Unexpected exception on worker thread: %s)
r   r   waitis_settimer   r   	Exceptionr   	exception)r   stopped	next_timeedelays        r   r   zRepeatingTask._run&   s    !#{{ 4 45++$$&		doo5IO 		+E16dkk&&u-@R@R@TG   OIAMNNOs   4C 	D#D  DN)
__name__
__module____qualname____doc__floatr   r   r   r   r    r   r   r   r      s1    $ $u $ $Ur   r   )	ldclient.impl.utilr   	threadingr   r   r"   typingr   r   r.   r   r   <module>r2      s    " #  +U +Ur   