PlasmaCalcs.tools.timing.TickingWatch
- class PlasmaCalcs.tools.timing.TickingWatch(interval, *, wait=True, _t_mark_key='tick')
Bases:
StopwatchStopwatch that also “ticks” every N seconds.No active background process; just checks time, when queried. See self.tick().self.tick() returns whether at least N seconds have passed since the “marked” time,AND if the result is True, sets the “marked” time to now.self.nticks tracks the number of times self.tick() ever returned True.note: self.nticks resets to 0 when self.reset() is called.
- interval: int (possibly negative or 0)
- N. Number of seconds between ticks.>0 –> minimum time between calls to self.tick() returning True.=0 –> self.tick() will always return True.<0 –> self.tick() will always return False.
- wait: bool, default True
- whether the first True tick() may require waiting.False –> the first call to self.tick() will always give True.True –> the first call to self.tick() will only give True if self.interval seconds have passed.
- _t_mark_key: hashable object, default ‘tick’
- key associated with the “marked” time for ticking.note: if None, ticks are stored in the “default marked time” key; see Stopwatch for details.
- __init__(interval, *, wait=True, _t_mark_key='tick')
Methods
__init__(interval, *[, wait, _t_mark_key])get_marked_time([key])mark_time([key, _time])now()reset(**kw)tick()time_elapsed_string([as_string])time_since_mark([key])Attributes
- get_marked_time(key=None)
- returns marked time associated with this key.
- get_marked_times()
- returns dict of marked times.
- mark_time(key=None, *, _time=None)
- sets “marked” time to now (or _time, if provided).
- key: hashable object, default None
- associate marked time with this key. (None –> “default” marked time.)
- static now()
- returns time.time(). Provided as a static method for convenience.
- reset(**kw)
- resets the “t=0” time, also set self.nticks=0.
- tick()
- returns True if enough time has passed for the next tick.If True, also “marks” the current time, as the previous tick time.“Enough time” usually means at least self.interval seconds.Exceptions:if not self.waiting, return True (and set self.waiting = False)if interval < 0, return False.
- property time
- alias to self.time_since_reset
- property time_elapsed
- alias to self.time_since_reset
- time_elapsed_string(as_string=False)
- returns string ‘Total time elapsed: {:.2f} seconds.’.format(self.time_since_reset())
- time_since_mark(key=None)
- returns time [in seconds] since the “mark” time on this watch.“mark” set by self.mark_time(). Also set when created or reset().
- key: hashable object, default None
- “marked time” associated with this key.
- time_since_reset()
- returns time [in seconds] since the “t=0” time on this watch.“t=0” set by self.reset(). Also set when created.
- time_since_tick()
- get time since last tick. Note: does not edit the “marked” time.