diff options
Diffstat (limited to 'state_tracker.py')
| -rw-r--r-- | state_tracker.py | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/state_tracker.py b/state_tracker.py index 62eb183..66d2de6 100644 --- a/state_tracker.py +++ b/state_tracker.py @@ -6,7 +6,6 @@ polling. StateTracker expects to be invoked periodically to maintain state whereas the others automatically update themselves and, optionally, expose an event for client code to wait on state changes. - """ import datetime @@ -29,7 +28,6 @@ class StateTracker(ABC): invoked via the heartbeat() method. This method, in turn, invokes update() with update_ids according to a schedule / periodicity provided to the c'tor. - """ def __init__(self, update_ids_to_update_secs: Dict[str, float]) -> None: @@ -40,7 +38,6 @@ class StateTracker(ABC): Note that, when more than one update is overdue, they will be invoked in order by their update_ids so care in choosing these identifiers may be in order. - """ self.update_ids_to_update_secs = update_ids_to_update_secs self.last_reminder_ts: Dict[str, Optional[datetime.datetime]] = {} @@ -61,7 +58,6 @@ class StateTracker(ABC): The now param is the approximate current timestamp and the last_invocation param is the last time you were invoked (or None on the first invocation) - """ pass @@ -77,8 +73,8 @@ class StateTracker(ABC): Setting force_all_updates_to_run will invoke all updates (ordered by update_id) immediately ignoring whether or not they are due. - """ + self.now = datetime.datetime.now(tz=pytz.timezone("US/Pacific")) for update_id in sorted(self.last_reminder_ts.keys()): if force_all_updates_to_run: @@ -109,7 +105,6 @@ class AutomaticStateTracker(StateTracker): """Just like HeartbeatCurrentState but you don't need to pump the heartbeat; it runs on a background thread. Call .shutdown() to terminate the updates. - """ @background_thread @@ -117,7 +112,6 @@ class AutomaticStateTracker(StateTracker): """Entry point for a background thread to own calling heartbeat() at regular intervals so that the main thread doesn't need to do so. - """ while True: if should_terminate.is_set(): @@ -150,8 +144,8 @@ class AutomaticStateTracker(StateTracker): def shutdown(self): """Terminates the background thread and waits for it to tear down. This may block for as long as self.sleep_delay. - """ + logger.debug('Setting shutdown event and waiting for background thread.') self.should_terminate.set() self.updater_thread.join() @@ -166,7 +160,7 @@ class WaitableAutomaticStateTracker(AutomaticStateTracker): simply timed out. If the return value is true, the instance should be reset() before wait is called again. - Example usage: + Example usage:: detector = waitable_presence.WaitableAutomaticStateSubclass() while True: @@ -177,7 +171,6 @@ class WaitableAutomaticStateTracker(AutomaticStateTracker): else: # Just a timeout; no need to reset. Maybe do something # else before looping up into wait again. - """ def __init__( |
