
    uYf<                         d dl Z d dlZd dlZd dlmZ ddlmZ  G d de j                        Z G d de      Z	 ej                  d	
       G d dej                               Z G d de      Zy)    N)service   )forksafec                   8     e Zd ZdZdZ	 	 d fd	Zd Zd Z xZS )PeriodicThreadzPeriodic thread.

    This class can be used to instantiate a worker thread that will run its `run_periodic` function every `interval`
    seconds.

    Tc                     t         t        |   |       || _        || _        || _        t        j                         | _        d| _	        y)aJ  Create a periodic thread.

        :param interval: The interval in seconds to wait between execution of the periodic function.
        :param target: The periodic function to execute every interval.
        :param name: The name of the thread.
        :param on_shutdown: The function to call when the thread shuts down.
        )nameTN)
superr   __init___target_on_shutdownintervalr   Eventquitdaemonselfr   targetr	   on_shutdown	__class__s        Y/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/ddtrace/internal/periodic.pyr   zPeriodicThread.__init__   sB     	nd,$,7' NN$	    c                 Z    | j                         r| j                  j                          yy)zStop the thread.N)is_aliver   setr   s    r   stopzPeriodicThread.stop,   s     ==?IIMMO r   c                     | j                   j                  | j                        s6| j                          | j                   j                  | j                        s6| j                  | j	                          yy)z%Run the target function periodically.N)r   waitr   r   r   r   s    r   runzPeriodicThread.run5   sR    ))../LLN ))../( )r   NN)	__name__
__module____qualname____doc___ddtrace_profiling_ignorer   r   r    __classcell__r   s   @r   r   r      s'     !% , r   r   c                   >     e Zd ZdZ	 	 d fd	Zd Z fdZd Z xZS )AwakeablePeriodicThreadzPeriodic thread that can be awakened on demand.

    This class can be used to instantiate a worker thread that will run its
    `run_periodic` function every `interval` seconds, or upon request.
    c                     t         t        |   ||||       t        j                         | _        t        j                         | _        t        j                         | _        y)z8Create a periodic thread that can be awakened on demand.N)	r
   r*   r   r   r   requestservedLock
awake_lockr   s        r   r   z AwakeablePeriodicThread.__init__D   sD     	%t5hkZ~~'nn&"--/r   c                     | j                   5  | j                  j                          | j                  j	                          | j                  j                          ddd       y# 1 sw Y   yxY w)zAwake the thread.N)r/   r-   clearr,   r   r   r   s    r   awakezAwakeablePeriodicThread.awakeR   sN    __ 	KKLLKK	 	 	s   AA%%A.c                 V    t         |           | j                  j                          y N)r
   r   r,   r   )r   r   s    r   r   zAwakeablePeriodicThread.stopY   s    r   c                    | j                   j                         s| j                          | j                  j	                  | j
                        rO| j                   j                         rnO| j                  j                          | j                  j                          | j                   j                         s| j                  | j                          yy)z2Run the target function periodically or on demand.N)
r   is_setr   r,   r   r   r1   r-   r   r   r   s    r   r    zAwakeablePeriodicThread.run]   s    ))""$LLN||  /99##%""$! ))""$ ( )r   r!   )	r"   r#   r$   r%   r   r2   r   r    r'   r(   s   @r   r*   r*   =   s$     * r   r*   F)eqc                        e Zd ZdZ ej
                  e      Z ej
                  ddd      Ze	Z
ed        Zej                  d        Zd Z fd	Z	 dd
Zed        Zd Z xZS )PeriodicServicez!A service that runs periodically.)typeNF)defaultinitreprc                     | j                   S r4   )	_intervalr   s    r   r   zPeriodicService.intervalu   s     ~~r   c                 N    || _         | j                  r|| j                  _        y y r4   )r?   _workerr   )r   values     r   r   zPeriodicService.intervalz   s#     <<$)DLL! r   c                    | j                  | j                  | j                  | j                  j                  d| j                  j
                  | j                        | _        | j                  j                          y)zStart the periodic service.:)r   r	   r   N)	__thread_class__r   periodicr   r#   r"   r   rA   start)r   argskwargss      r   _start_servicezPeriodicService._start_service   s`     ,,MM== NN55t~~7N7NO((	 - 
 	r   c                 `    | j                   j                          t        t        |   |i | y)zStop the periodic collector.N)rA   r   r
   r9   _stop_service)r   rH   rI   r   s      r   rL   zPeriodicService._stop_service   s)     	ot2DCFCr   c                 T    | j                   r| j                   j                  |       y y r4   )rA   join)r   timeouts     r   rN   zPeriodicService.join   s"    
 <<LLg& r   c                       y r4    rQ   r   r   r   zPeriodicService.on_shutdown       r   c                      y r4   rQ   r   s    r   rF   zPeriodicService.periodic   rR   r   r4   )r"   r#   r$   r%   attribfloatr?   rA   r   rE   propertyr   setterrJ   rL   rN   staticmethodr   rF   r'   r(   s   @r   r9   r9   l   s    +U#IdggdU;G%  __* *	D '  r   r9   c                       e Zd ZdZeZd Zy)AwakeablePeriodicServicezIA service that runs periodically but that can also be awakened on demand.c                 8    | j                   j                          y r4   )rA   r2   r   s    r   r2   zAwakeablePeriodicService.awake   s    r   N)r"   r#   r$   r%   r*   rE   r2   rQ   r   r   r[   r[      s    S.r   r[   )	threadingtypingrT   ddtrace.internalr    r   Threadr   r*   sServicer9   r[   rQ   r   r   <module>rd      sk       $ . Y%% . b, n , ^ 57goo 7 7t r   