add an interval validation for the RepeatingTimer
from abc import ABC, abstractmethod
from functools import wraps
+from logging import getLogger
from typing import Callable, NamedTuple
import time
@@ -64,14 +65,16 @@ class RepeatingTimer:
self._timer.schedule(self._interval, self._callback)
self._timer = timer
- self._interval = interval
+ self._interval = None
+ self.update_interval(interval)
self._callback = wrapped_callback
self._active = False
+ self._logger = getLogger()
if active:
self.start()
def start(self):
- if self._active:
+ if self._active or not self._interval:
return
self._active = True
self._timer.schedule(self._interval, self._callback)
@@ -83,4 +86,7 @@ class RepeatingTimer:
self._timer.cancel(self._callback)
def update_interval(self, interval):
+ if interval <= 0:
+ self._logger.debug("RepeatingTimer - incorrect interval {}".format(interval))
+ return
self._interval = interval
