···
from typing import Callable, Optional
+
from math import isfinite
from .logger import rootlog
···
description: Optional[str]
···
self.description = str(description)
self.last_called = float("-inf")
+
def check(self, force: bool = False) -> bool:
+
if (self.entered or not self.overdue) and not force:
with self, rootlog.nested(self.nested_message):
+
time_since_last = time.monotonic() - self.last_called
+
f"Time since last: {time_since_last:.2f}s"
+
if isfinite(time_since_last)
+
else "(not called yet)"
+
rootlog.info(last_message)
res = self.condition() # type: ignore
···
def overdue(self) -> bool:
return self.last_called + self.seconds_interval < time.monotonic()
+
def entered(self) -> bool:
+
# entry_count should never dip *below* zero
+
assert self.entry_count >= 0
+
return self.entry_count > 0
def __enter__(self) -> None:
def __exit__(self, exc_type, exc_value, traceback) -> None: # type: ignore
self.last_called = time.monotonic()