
    h                     b    d Z ddlZddlZddlZddlmZ  G d de      Z e       Z	d Z
d Zd Zy)	z-Run a target function on a background thread.    N)timec                   N    e Zd ZddZd Zd ZddZddZd Zd Z	d	 Z
d
 Zd Zy)PeriodicExecutorNc                     d| _         || _        || _        || _        d| _        d| _        || _        d| _        d| _        t        j                         | _        y)a  "Run a target function periodically on a background thread.

        If the target's return value is false, the executor stops.

        :Parameters:
          - `interval`: Seconds between calls to `target`.
          - `min_interval`: Minimum seconds between calls if `wake` is
            called very often.
          - `target`: A function.
          - `name`: A name to give the underlying thread.
        FN)_event	_interval_min_interval_target_stopped_thread_name_skip_sleep_thread_will_exit	threadingLock_lock)selfintervalmin_intervaltargetnames        \/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/pymongo/periodic_executor.py__init__zPeriodicExecutor.__init__   sT      !)
 !&^^%
    c                 `    d| j                   j                  | j                  t        |       fz  S )Nz<%s(name=%s) object at 0x%x>)	__class____name__r   idr   s    r   __repr__zPeriodicExecutor.__repr__5   s-    -NN##TZZD1; ; 	;r   c                    | j                   5  | j                  r	 | j                  j                          d| _        d| _        ddd       d}	 | j                  xr | j                  j                         }|sht        j                  | j                  | j                        }d|_        t        j                  |      | _        t        |        |j                          yy# t        $ r Y w xY w# 1 sw Y   xY w# t        $ r Y w xY w)zgStart. Multiple calls have no effect.

        Not safe to call from multiple threads at once.
        FN)r   r   T)r   r   r   joinReferenceErrorr   is_aliver   Thread_runr   daemonweakrefproxy_register_executorstart)r   startedthreads      r   openzPeriodicExecutor.open9   s    
 ZZ 	"%%
LL%%' &+D"!DM	" 	ll>t||'<'<'>G
 %%TYYTZZHF FM"==0DLt$LLN  & 	" 	"   		s?   C0C!C0(C< !	C-*C0,C--C00C9<	DDc                     d| _         y)zStop. To restart, call open().

        The dummy parameter allows an executor's close method to be a weakref
        callback; see monitor.py.
        TN)r   )r   dummys     r   closezPeriodicExecutor.closeY   s     r   c                     | j                   	 | j                   j                  |       y y # t        t        f$ r Y y w xY wN)r   r"   r#   RuntimeError)r   timeouts     r   r"   zPeriodicExecutor.joina   sA    <<#!!'* $ #L1 s   + ==c                     d| _         y)z!Execute the target function soon.TN)r   r   s    r   wakezPeriodicExecutor.wakei   s	    r   c                     || _         y r3   )r   )r   new_intervals     r   update_intervalz PeriodicExecutor.update_intervalm   s	    %r   c                     d| _         y )NT)r   r   s    r   
skip_sleepzPeriodicExecutor.skip_sleepp   s
    r   c                     | j                   5  | j                  rd| _        	 d d d        y	 d d d        y# 1 sw Y   y xY wNTF)r   r   r   r   s    r   __should_stopzPeriodicExecutor.__should_stops   s?    ZZ 	}})-&	 	 		 	 	s   55>c                    | j                         s	 | j                         sd| _        y 	 | j
                  rd| _        nvt               | j                  z   }| j                  sSt               |k  rFt        j                  | j                         | j                  rn| j                  st               |k  rFd| _        | j                         sy y #  | j                  5  d| _        d| _        d d d         # 1 sw Y    xY wxY wr>   )_PeriodicExecutor__should_stopr
   r   r   r   r   _timer   r   sleepr	   r   )r   deadlines     r   r&   zPeriodicExecutor._runz   s    $$&	||~$(DM & #(  7T^^3--EGh,>JJt112{{ --EGh,>
  DK+ $$&
ZZ 2$(DM-1D*2 	2 s#   C DC5,	D5C>	:Dr3   )r   
__module____qualname__r   r    r.   r1   r"   r7   r:   r<   rA   r&    r   r   r   r      s5    &8;@&  r   r   c                 b    t        j                  | t              }t        j	                  |       y r3   )r(   ref_on_executor_deleted
_EXECUTORSadd)executorrI   s     r   r*   r*      s    
++h 4
5CNN3r   c                 .    t         j                  |        y r3   )rK   remove)rI   s    r   rJ   rJ      s    cr   c                      t         y t        t               } | D ]  } |       }|s|j                           | D ]  } |       }|s|j                  d        d }y )N   )rK   listr1   r"   )	executorsrI   rM   s      r   _shutdown_executorsrT      sj     Z I  5NN  5MM!
 Hr   )__doc__r   r   r(   pymongo.monotonicrB   objectr   setrK   r*   rJ   rT   rG   r   r   <module>rY      s=    4    +x v x B U

r   