Improved periodical to forgive skipped beats

This commit is contained in:
Odd Stråbø 2021-11-08 21:39:21 +01:00
parent 7a61f60ecc
commit 9fc8db577a

View file

@ -307,8 +307,13 @@ class Periodical:
now = time.time()
if (now - self.prev) >= self.interval:
self.prev += self.interval
skipped, overshoot = divmod(now - self.prev, self.interval)
skipped -= 1
if skipped:
log("Skipped:", skipped, overshoot, now - self.prev, self.interval)
self.prev = now - overshoot
return True
return False