From 8f73bcffe4305bbd49103d4adfe82f5a3d3c88e9 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 5 Dec 2024 13:35:44 -0800 Subject: [PATCH] micd: fix fake lagging warnings (#34158) * micd: fix fake lagging warnings * fix it properly * simple --- common/realtime.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/realtime.py b/common/realtime.py index dd97ea3d787ccf..854c3ca5922bf3 100644 --- a/common/realtime.py +++ b/common/realtime.py @@ -48,13 +48,13 @@ class Ratekeeper: def __init__(self, rate: float, print_delay_threshold: float | None = 0.0) -> None: """Rate in Hz for ratekeeping. print_delay_threshold must be nonnegative.""" self._interval = 1. / rate - self._next_frame_time = time.monotonic() + self._interval self._print_delay_threshold = print_delay_threshold self._frame = 0 self._remaining = 0.0 self._process_name = getproctitle() self._dts = deque([self._interval], maxlen=100) - self._last_monitor_time = time.monotonic() + self._last_monitor_time = -1. + self._next_frame_time = -1. @property def frame(self) -> int: @@ -79,6 +79,10 @@ def keep_time(self) -> bool: # Monitors the cumulative lag, but does not enforce a rate def monitor_time(self) -> bool: + if self._last_monitor_time < 0: + self._next_frame_time = time.monotonic() + self._interval + self._last_monitor_time = time.monotonic() + prev = self._last_monitor_time self._last_monitor_time = time.monotonic() self._dts.append(self._last_monitor_time - prev)