diff -r 15d7bd79d9e8 -r 6c9cfdbe94dc svghmi/svghmi_server.py --- a/svghmi/svghmi_server.py Tue Jan 21 13:55:03 2020 +0100 +++ b/svghmi/svghmi_server.py Thu Jan 23 11:22:09 2020 +0100 @@ -78,17 +78,20 @@ return 0 class Watchdog(object): - def __init__(self, initial_timeout, callback): + def __init__(self, initial_timeout, interval, callback): self._callback = callback self.lock = RLock() self.initial_timeout = initial_timeout + self.interval = interval self.callback = callback with self.lock: self._start() - def _start(self): - self.timer = Timer(self.initial_timeout, self.trigger) - self.timer.start() + def _start(self, rearm=False): + duration = self.interval if rearm else self.initial_timeout + if duration: + self.timer = Timer(duration, self.trigger) + self.timer.start() def _stop(self): if self.timer is not None: @@ -102,7 +105,7 @@ def feed(self): with self.lock: self._stop() - self._start() + self._start(rearm=True) def trigger(self): self._callback() @@ -162,7 +165,7 @@ # Called by PLCObject at start def _runtime_svghmi0_start(): - global svghmi_listener, svghmi_root, svghmi_send_thread, svghmi_watchdog + global svghmi_listener, svghmi_root, svghmi_send_thread svghmi_root = Resource() svghmi_root.putChild("ws", WebSocketResource(HMIWebSocketServerFactory())) @@ -173,15 +176,10 @@ svghmi_send_thread = Thread(target=SendThreadProc, name="SVGHMI Send") svghmi_send_thread.start() - svghmi_watchdog = Watchdog(5, watchdog_trigger) # Called by PLCObject at stop def _runtime_svghmi0_stop(): - global svghmi_listener, svghmi_root, svghmi_send_thread, svghmi_session, svghmi_watchdog - - if svghmi_watchdog is not None: - svghmi_watchdog.cancel() - svghmi_watchdog = None + global svghmi_listener, svghmi_root, svghmi_send_thread, svghmi_session if svghmi_session is not None: svghmi_session.close()