File: //lib/python3/dist-packages/twisted/internet/__pycache__/task.cpython-38.pyc
U
��W[�y � @ s� d Z ddlmZmZ eZddlZddlZddlZddl m
Z
ddlmZ ddlm
Z
ddlmZ ddlmZ dd lmZ dd
lmZmZ ddlmZ ddlmZ G d
d� d�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Z G dd� de�Z!G dd� de�Z"G dd� de�Z#G dd� de$�Z%dZ&d d!� Z'G d"d#� d#e$�Z(G d$d%� d%e$�Z)e)� Z*d&d'� Z+d(d)� Z,e
e�G d*d+� d+��Z-d,d-� Z.d1d/d0�Z/dd+dd%d'd-d0gZ0dS )2z)
Scheduling utility methods and classes.
� )�division�absolute_importN)�implementer)�log)�reflect)�_getDeprecationWarningString)�Failure)�Version)�base�defer)�IReactorTime)�ReactorNotRunningc @ s� e Zd ZdZdZdZdZdZdZdZ dd� Z
edd� �Zdd � Z
ee
�Z
d
d� Zdd
d�Zdd� Zdd� Zdd� Zdd� Zdd� ZdS )�LoopingCalla� Call a function repeatedly.
If C{f} returns a deferred, rescheduling will not take place until the
deferred has fired. The result value is ignored.
@ivar f: The function to call.
@ivar a: A tuple of arguments to pass the function.
@ivar kw: A dictionary of keyword arguments to pass to the function.
@ivar clock: A provider of
L{twisted.internet.interfaces.IReactorTime}. The default is
L{twisted.internet.reactor}. Feel free to set this to
something else, but it probably ought to be set *before*
calling L{start}.
@type running: C{bool}
@ivar running: A flag which is C{True} while C{f} is scheduled to be called
(or is currently being called). It is set to C{True} when L{start} is
called and set to C{False} when L{stop} is called or if C{f} raises an
exception. In either case, it will be C{False} by the time the
C{Deferred} returned by L{start} fires its callback or errback.
@type _realLastTime: C{float}
@ivar _realLastTime: When counting skips, the time at which the skip
counter was last invoked.
@type _runAtStart: C{bool}
@ivar _runAtStart: A flag indicating whether the 'now' argument was passed
to L{LoopingCall.start}.
NFc O s( || _ || _|| _ddlm} || _d S �Nr ��reactor)�f�a�kw�twisted.internetr �clock)�selfr r r r � r �7/usr/lib/python3/dist-packages/twisted/internet/task.py�__init__D s
zLoopingCall.__init__c C s. t dtdddd�dd�}tj|tdd� | jS ) z�
DEPRECATED. L{Deferred} fired when loop stops or fails.
Use the L{Deferred} returned by L{LoopingCall.start}.
z*twisted.internet.task.LoopingCall.deferredZTwisted� r z the deferred returned by start())Zreplacement� )�
stacklevel)r r �warnings�warn�DeprecationWarning� _deferred)r Z
warningStringr r r �deferredK s �zLoopingCall.deferredc s � �fdd�}| |��d�_ �S )aW
An alternate constructor for L{LoopingCall} that makes available the
number of calls which should have occurred since it was last invoked.
Note that this number is an C{int} value; It represents the discrete
number of calls that should have been made. For example, if you are
using a looping call to display an animation with discrete frames, this
number would be the number of frames to advance.
The count is normally 1, but can be higher. For example, if the reactor
is blocked and takes too long to invoke the L{LoopingCall}, a Deferred
returned from a previous call is not fired before an interval has
elapsed, or if the callable itself blocks for longer than an interval,
preventing I{itself} from being called.
When running with an interval if 0, count will be always 1.
@param countCallable: A callable that will be invoked each time the
resulting LoopingCall is run, with an integer specifying the number
of calls that should have been invoked.
@type countCallable: 1-argument callable which takes an C{int}
@return: An instance of L{LoopingCall} with call counting enabled,
which provides the count as the first positional argument.
@rtype: L{LoopingCall}
@since: 9.0
c s| �j �� } �jdkr"| �_� d�S �j}|d krF�j}�jrF|�j8 }��|�}��| �}|| }|dkrx| �_� |�S d S )Nr � )r �seconds�interval�
_realLastTime� starttime�_runAtStart�_intervalOf)�nowZlastTimeZlastIntervalZthisInterval�count��
countCallabler r r �counterz s
z&LoopingCall.withCount.<locals>.counterN)r&