Merge branch 'watchdog' into for_webui
# Conflicts: # src-python/webui_controller.py # src-python/webui_mainloop.py
This commit is contained in:
@@ -109,6 +109,14 @@ class Config:
|
|||||||
def MAX_SPEAKER_THRESHOLD(self):
|
def MAX_SPEAKER_THRESHOLD(self):
|
||||||
return self._MAX_SPEAKER_THRESHOLD
|
return self._MAX_SPEAKER_THRESHOLD
|
||||||
|
|
||||||
|
@property
|
||||||
|
def WATCHDOG_TIMEOUT(self):
|
||||||
|
return self._WATCHDOG_TIMEOUT
|
||||||
|
|
||||||
|
@property
|
||||||
|
def WATCHDOG_INTERVAL(self):
|
||||||
|
return self._WATCHDOG_INTERVAL
|
||||||
|
|
||||||
# Read Write
|
# Read Write
|
||||||
@property
|
@property
|
||||||
def ENABLE_SPEAKER2CHATBOX(self):
|
def ENABLE_SPEAKER2CHATBOX(self):
|
||||||
@@ -993,6 +1001,8 @@ class Config:
|
|||||||
|
|
||||||
self._MAX_MIC_THRESHOLD = 2000
|
self._MAX_MIC_THRESHOLD = 2000
|
||||||
self._MAX_SPEAKER_THRESHOLD = 4000
|
self._MAX_SPEAKER_THRESHOLD = 4000
|
||||||
|
self._WATCHDOG_TIMEOUT = 60
|
||||||
|
self._WATCHDOG_INTERVAL = 20
|
||||||
|
|
||||||
# Read Write
|
# Read Write
|
||||||
self._ENABLE_TRANSLATION = False
|
self._ENABLE_TRANSLATION = False
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ from models.translation.translation_utils import checkCTranslate2Weight, downloa
|
|||||||
from models.transcription.transcription_whisper import checkWhisperWeight, downloadWhisperWeight
|
from models.transcription.transcription_whisper import checkWhisperWeight, downloadWhisperWeight
|
||||||
from models.overlay.overlay import Overlay
|
from models.overlay.overlay import Overlay
|
||||||
from models.overlay.overlay_image import OverlayImage
|
from models.overlay.overlay_image import OverlayImage
|
||||||
|
from models.watchdog.watchdog import Watchdog
|
||||||
|
|
||||||
class threadFnc(Thread):
|
class threadFnc(Thread):
|
||||||
def __init__(self, fnc, end_fnc=None, daemon=True, *args, **kwargs):
|
def __init__(self, fnc, end_fnc=None, daemon=True, *args, **kwargs):
|
||||||
@@ -102,6 +103,7 @@ class Model:
|
|||||||
self.mic_mute_status = None
|
self.mic_mute_status = None
|
||||||
self.mic_mute_status_check = None
|
self.mic_mute_status_check = None
|
||||||
self.kks = kakasi()
|
self.kks = kakasi()
|
||||||
|
self.watchdog = Watchdog(config.WATCHDOG_TIMEOUT, config.WATCHDOG_INTERVAL)
|
||||||
|
|
||||||
def checkCTranslatorCTranslate2ModelWeight(self):
|
def checkCTranslatorCTranslate2ModelWeight(self):
|
||||||
return checkCTranslate2Weight(config.PATH_LOCAL, config.CTRANSLATE2_WEIGHT_TYPE)
|
return checkCTranslate2Weight(config.PATH_LOCAL, config.CTRANSLATE2_WEIGHT_TYPE)
|
||||||
@@ -723,4 +725,21 @@ class Model:
|
|||||||
def shutdownOverlay(self):
|
def shutdownOverlay(self):
|
||||||
self.overlay.shutdownOverlay()
|
self.overlay.shutdownOverlay()
|
||||||
|
|
||||||
|
def startWatchdog(self):
|
||||||
|
self.th_watchdog = threadFnc(self.watchdog.start)
|
||||||
|
self.th_watchdog.daemon = True
|
||||||
|
self.th_watchdog.start()
|
||||||
|
|
||||||
|
def feedWatchdog(self):
|
||||||
|
self.watchdog.feed()
|
||||||
|
|
||||||
|
def setWatchdogCallback(self, callback):
|
||||||
|
self.watchdog.setCallback(callback)
|
||||||
|
|
||||||
|
def stopWatchdog(self):
|
||||||
|
if isinstance(self.th_watchdog, threadFnc):
|
||||||
|
self.th_watchdog.stop()
|
||||||
|
self.th_watchdog.join()
|
||||||
|
self.th_watchdog = None
|
||||||
|
|
||||||
model = Model()
|
model = Model()
|
||||||
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)
|
||||||
@@ -1535,6 +1535,25 @@ class Controller:
|
|||||||
th_download.daemon = True
|
th_download.daemon = True
|
||||||
th_download.start()
|
th_download.start()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def startWatchdog(*args, **kwargs) -> dict:
|
||||||
|
model.startWatchdog()
|
||||||
|
return {"status":200, "result":True}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def feedWatchdog(*args, **kwargs) -> dict:
|
||||||
|
model.feedWatchdog()
|
||||||
|
return {"status":200, "result":True}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setWatchdogCallback(callback) -> dict:
|
||||||
|
model.setWatchdogCallback(callback)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def stopWatchdog(*args, **kwargs) -> dict:
|
||||||
|
model.stopWatchdog()
|
||||||
|
return {"status":200, "result":True}
|
||||||
|
|
||||||
def init(self, *args, **kwargs) -> None:
|
def init(self, *args, **kwargs) -> None:
|
||||||
printLog("Start Initialization")
|
printLog("Start Initialization")
|
||||||
|
|
||||||
@@ -1599,3 +1618,5 @@ class Controller:
|
|||||||
self.setEnableAutoSpeakerSelect()
|
self.setEnableAutoSpeakerSelect()
|
||||||
|
|
||||||
printLog("End Initialization")
|
printLog("End Initialization")
|
||||||
|
|
||||||
|
self.startWatchdog()
|
||||||
@@ -305,11 +305,16 @@ mapping = {
|
|||||||
"/set/data/osc_port": {"status": True, "variable":controller.setOscPort},
|
"/set/data/osc_port": {"status": True, "variable":controller.setOscPort},
|
||||||
|
|
||||||
"/run/open_filepath_config_file": {"status": True, "variable":controller.openFilepathConfigFile},
|
"/run/open_filepath_config_file": {"status": True, "variable":controller.openFilepathConfigFile},
|
||||||
|
|
||||||
|
# "/run/start_watchdog": {"status": True, "variable":controller.startWatchdog},
|
||||||
|
"/run/feed_watchdog": {"status": True, "variable":controller.feedWatchdog},
|
||||||
|
# "/run/stop_watchdog": {"status": True, "variable":controller.stopWatchdog},
|
||||||
}
|
}
|
||||||
|
|
||||||
class Main:
|
class Main:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.queue = Queue()
|
self.queue = Queue()
|
||||||
|
self.main_loop = True
|
||||||
|
|
||||||
def receiver(self) -> None:
|
def receiver(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
@@ -328,7 +333,7 @@ class Main:
|
|||||||
th_receiver.daemon = True
|
th_receiver.daemon = True
|
||||||
th_receiver.start()
|
th_receiver.start()
|
||||||
|
|
||||||
def handleRequest(self, endpoint, data=None):
|
def handleRequest(self, endpoint, data=None) -> tuple:
|
||||||
handler = mapping.get(endpoint)
|
handler = mapping.get(endpoint)
|
||||||
if handler is None:
|
if handler is None:
|
||||||
response = "Invalid endpoint"
|
response = "Invalid endpoint"
|
||||||
@@ -371,15 +376,19 @@ class Main:
|
|||||||
th_handler.daemon = True
|
th_handler.daemon = True
|
||||||
th_handler.start()
|
th_handler.start()
|
||||||
|
|
||||||
def loop(self) -> None:
|
def start(self) -> None:
|
||||||
while True:
|
while self.main_loop:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
def stop(self) -> None:
|
||||||
|
self.main_loop = False
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main = Main()
|
main = Main()
|
||||||
main.startReceiver()
|
main.startReceiver()
|
||||||
main.startHandler()
|
main.startHandler()
|
||||||
|
|
||||||
|
controller.setWatchdogCallback(main.stop)
|
||||||
controller.init()
|
controller.init()
|
||||||
|
|
||||||
# mappingのすべてのstatusをTrueにする
|
# mappingのすべてのstatusをTrueにする
|
||||||
@@ -389,7 +398,7 @@ if __name__ == "__main__":
|
|||||||
process = "main"
|
process = "main"
|
||||||
match process:
|
match process:
|
||||||
case "main":
|
case "main":
|
||||||
main.loop()
|
main.start()
|
||||||
|
|
||||||
case "test":
|
case "test":
|
||||||
for _ in range(100):
|
for _ in range(100):
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ const StartPythonFacadeComponent = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasRunRef.current) {
|
if (!hasRunRef.current) {
|
||||||
asyncStartPython().then((result) => {
|
asyncStartPython().then((result) => {
|
||||||
|
startFeedingToWatchDog();
|
||||||
|
|
||||||
getUiLanguage();
|
getUiLanguage();
|
||||||
getUiScaling();
|
getUiScaling();
|
||||||
getMessageLogUiScaling();
|
getMessageLogUiScaling();
|
||||||
@@ -246,3 +248,11 @@ const TransparencyController = () => {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||||
|
const startFeedingToWatchDog = () => {
|
||||||
|
const { asyncStdoutToPython } = useStdoutToPython();
|
||||||
|
setInterval(() => {
|
||||||
|
asyncStdoutToPython("/run/feed_watchdog");
|
||||||
|
}, 20000); // 20000ミリ秒 = 20秒
|
||||||
|
};
|
||||||
@@ -82,6 +82,7 @@ export const useReceiveRoutes = () => {
|
|||||||
|
|
||||||
|
|
||||||
const routes = {
|
const routes = {
|
||||||
|
"/run/feed_watchdog": () => {},
|
||||||
// Main Page
|
// Main Page
|
||||||
// Page Controls
|
// Page Controls
|
||||||
"/get/data/main_window_sidebar_compact_mode": updateIsMainPageCompactMode,
|
"/get/data/main_window_sidebar_compact_mode": updateIsMainPageCompactMode,
|
||||||
|
|||||||
Reference in New Issue
Block a user