
    ∋d                       U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZg dZi Z	de
d<   e	                    ej                   e	                    ej                   ej        dk    Zej        dk    Zej        dk    Zd	 Zd
 Zej        dk    rd dlmZ dS d dlZd dlZd dlmZmZ d dlmZ d dlmZ d dlm Z   G d d          ZdS )    )annotationsN)logging_namesPeriodicCallback	to_thread	randbyteszdict[str | int, int | str]r   linuxdarwinwin32c                 \    t          j        dt          d           t          j        | i |S )Nz_to_thread is deprecated and will be removed in a future release; use asyncio.to_thread instead.   
stacklevel)warningswarnDeprecationWarningasyncior   argskwargss     9lib/python3.11/site-packages/distributed/compatibility.pyr   r      s<    Mi   
 d-f---    c                 \    t          j        dt          d           t          j        | i |S )Nz^randbytes is deprecated and will be removed in a future release; use random.randbytes instead.r   r   )r   r   r   randomr   r   s     r   r   r      s<    Mh   
 T,V,,,r   )   r   r   r   )r   )	AwaitableCallable)isawaitable)IOLoop)app_logc                  N    e Zd ZdZ	 dddZddZddZddZddZddZ	ddZ
dS )r   a  Schedules the given callback to be called periodically.

        The callback is called every ``callback_time`` milliseconds when
        ``callback_time`` is a float. Note that the timeout is given in
        milliseconds, while most other time-related functions in Tornado use
        seconds. ``callback_time`` may alternatively be given as a
        `datetime.timedelta` object.

        If ``jitter`` is specified, each callback time will be randomly selected
        within a window of ``jitter * callback_time`` milliseconds.
        Jitter can be used to reduce alignment of events with similar periods.
        A jitter of 0.1 means allowing a 10% variation in callback time.
        The window is centered on ``callback_time`` so the total number of calls
        within a given interval should not be significantly affected by adding
        jitter.

        If the callback runs for longer than ``callback_time`` milliseconds,
        subsequent invocations will be skipped to get back on schedule.

        `start` must be called after the `PeriodicCallback` is created.

        .. versionchanged:: 5.0
        The ``io_loop`` argument (deprecated since version 4.1) has been removed.

        .. versionchanged:: 5.1
        The ``jitter`` argument is added.

        .. versionchanged:: 6.2
        If the ``callback`` argument is a coroutine, and a callback runs for
        longer than ``callback_time``, subsequent invocations will be skipped.
        Previously this was only true for regular functions, not coroutines,
        which were "fire-and-forget" for `PeriodicCallback`.

        The ``callback_time`` argument now accepts `datetime.timedelta` objects,
        in addition to the previous numeric milliseconds.
        r   callbackCallable[[], Awaitable | None]callback_timedatetime.timedelta | floatjitterfloatreturnNonec                    || _         t          |t          j                  r|t          j        d          z  | _        n|dk    rt          d          || _        || _        d| _        d | _        d S )N   )millisecondsr   z4Periodic callback must have a positive callback_timeF)	r!   
isinstancedatetime	timedeltar#   
ValueErrorr%   _running_timeout)selfr!   r#   r%   s       r   __init__zPeriodicCallback.__init___   s     %DM-);<< 3%2X5GUV5W5W5W%W"" A%%$N   &3" DK!DM DMMMr   c                    t          j                    | _        d| _        | j                                        | _        |                                  dS )zStarts the timer.TN)r   currentio_loopr0   time_next_timeout_schedule_nextr2   s    r   startzPeriodicCallback.startr   sH    
 ">++DL DM!%!2!2!4!4D!!!!!r   c                r    d| _         | j        (| j                            | j                   d| _        dS dS )zStops the timer.FN)r0   r1   r6   remove_timeoutr:   s    r   stopzPeriodicCallback.stop|   s<    !DM}(++DM::: $ )(r   boolc                    | j         S )znReturns ``True`` if this `.PeriodicCallback` has been started.

            .. versionadded:: 4.1
            )r0   r:   s    r   
is_runningzPeriodicCallback.is_running   s    
 = r   c                ,  K   | j         sd S 	 |                                 }|t          |          r| d {V  n,# t          $ r t	          j        d| j        d           Y nw xY w|                                  d S # |                                  w xY w)NzException in callback %rT)exc_info)r0   r!   r   	Exceptionr   errorr9   )r2   vals     r   _runzPeriodicCallback._run   s      = &mmoo?{3'7'7?IIIIIII X X X8$-RVWWWWWWX ##%%%%%##%%%%s&   -; A= &A$!A= #A$$A= =Bc                    | j         rX|                     | j                                                   | j                            | j        | j                  | _        d S d S )N)r0   _update_nextr6   r7   add_timeoutr8   rG   r1   r:   s    r   r9   zPeriodicCallback._schedule_next   s]    } X!!$,"3"3"5"5666 $ 8 89KTY W WX Xr   current_timec                   | j         dz  }| j        r$|d| j        t          j                    dz
  z  z   z  }| j        |k    r5| xj        t	          j        || j        z
  |z            dz   |z  z  c_        d S | xj        |z  c_        d S )Ng     @@r*   g      ?)r#   r%   r   r8   mathfloor)r2   rK   callback_time_secs      r   rI   zPeriodicCallback._update_next   s     $ 2V ;{ Q!Q$+39N*O%PP!!\11
 ""Jt/A AEVVWW%'& &""""& ""&77""""r   N)r   )r!   r"   r#   r$   r%   r&   r'   r(   )r'   r(   )r'   r?   )rK   r&   r'   r(   )__name__
__module____qualname____doc__r3   r;   r>   rA   rG   r9   rI    r   r   r   r   9   s        #	 #	R 		! 	! 	! 	! 	!&	" 	" 	" 	"	% 	% 	% 	%	! 	! 	! 	!
	& 
	& 
	& 
	&	X 	X 	X 	X
	8 	8 	8 	8 	8 	8r   r   )!
__future__r   r   loggingr   sysr   tornado__all__r   __annotations__update_levelToName_nameToLevelplatformLINUXMACOSWINDOWSr   r   version_infotornado.ioloopr   r-   rM   collections.abcr   r   inspectr   r   tornado.logr   rT   r   r   <module>rg      s   " " " " " " "    



  
I
I
I,. . . . .   W) * * *   W) * * * 
,'
!. . .- - - <''//////// OOOKKK33333333######%%%%%%######8 8 8 8 8 8 8 8 8 8r   