Merge branch 'watchdog' into for_webui

# Conflicts:
#	src-python/webui_controller.py
#	src-python/webui_mainloop.py
This commit is contained in:
misyaguziya
2024-10-10 22:36:23 +09:00
7 changed files with 97 additions and 5 deletions

View 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)