ui: kick watchdog (#35460)

* kick watchdog

* use global

* use monotonic
This commit is contained in:
Dean Lee
2025-06-06 04:14:57 +08:00
committed by GitHub
parent 8aadf02b2f
commit 23ea85dca6
3 changed files with 27 additions and 2 deletions
+22
View File
@@ -0,0 +1,22 @@
import os
import time
import struct
from openpilot.system.hardware.hw import Paths
WATCHDOG_FN = f"{Paths.shm_path()}/wd_"
_LAST_KICK = 0.0
def kick_watchdog():
global _LAST_KICK
current_time = time.monotonic()
if current_time - _LAST_KICK < 1.0:
return
try:
with open(f"{WATCHDOG_FN}{os.getpid()}", 'wb') as f:
f.write(struct.pack('<Q', int(current_time * 1e9)))
f.flush()
_LAST_KICK = current_time
except OSError:
pass
+4
View File
@@ -1,10 +1,12 @@
#!/usr/bin/env python3
import pyray as rl
from openpilot.common.watchdog import kick_watchdog
from openpilot.system.ui.lib.application import gui_app
from openpilot.selfdrive.ui.layouts.main import MainLayout
from openpilot.selfdrive.ui.ui_state import ui_state
def main():
gui_app.init_window("UI")
main_layout = MainLayout()
@@ -15,6 +17,8 @@ def main():
main_layout.render(rl.Rectangle(0, 0, gui_app.width, gui_app.height))
kick_watchdog()
if __name__ == "__main__":
main()
+1 -2
View File
@@ -16,9 +16,8 @@ import openpilot.system.sentry as sentry
from openpilot.common.basedir import BASEDIR
from openpilot.common.params import Params
from openpilot.common.swaglog import cloudlog
from openpilot.system.hardware.hw import Paths
from openpilot.common.watchdog import WATCHDOG_FN
WATCHDOG_FN = f"{Paths.shm_path()}/wd_"
ENABLE_WATCHDOG = os.getenv("NO_WATCHDOG") is None