Preventing buffer overflow

This commit is contained in:
Maximilian Giller 2019-04-14 10:32:11 +02:00
parent 5b858bc121
commit 0e0803a5e6

View file

@ -1,6 +1,7 @@
from datetime import datetime, timedelta
min_sleep_minutes = 0
max_history_entries = 25
class LoopTimer (object):
"""Manages loop times and sleeps until
@ -19,6 +20,10 @@ class LoopTimer (object):
def __add_beginning__ (self, time):
self.loop_history.append((time,))
if len(self.loop_history) > max_history_entries:
dif = len(self.loop_history) - max_history_entries
self.loop_history = self.loop_history[dif:]
def __add_ending__ (self, time):
current = self.get_current()
self.loop_history[-1] = (current[0], time)