Merge branch 'watchdog' into for_webui
# Conflicts: # src-python/webui_controller.py # src-python/webui_mainloop.py
This commit is contained in:
22
src-python/models/watchdog/watchdog.py
Normal file
22
src-python/models/watchdog/watchdog.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from typing import Callable
|
||||
import time
|
||||
from utils import printLog
|
||||
|
||||
class Watchdog:
|
||||
def __init__(self, timeout:int=60, interval:int=20):
|
||||
self.timeout = timeout
|
||||
self.interval = interval
|
||||
self.last_feed_time = time.time()
|
||||
|
||||
def feed(self):
|
||||
self.last_feed_time = time.time()
|
||||
|
||||
def setCallback(self, callback):
|
||||
self.callback = callback
|
||||
|
||||
def start(self):
|
||||
if time.time() - self.last_feed_time > self.timeout:
|
||||
printLog("Watchdog timeout! Shutting down...")
|
||||
if isinstance(self.callback, Callable):
|
||||
self.callback()
|
||||
time.sleep(self.interval)
|
||||
Reference in New Issue
Block a user