Skip to content

Commit 23ea85d

Browse files
authored
ui: kick watchdog (#35460)
* kick watchdog * use global * use monotonic
1 parent 8aadf02 commit 23ea85d

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

common/watchdog.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
import time
3+
import struct
4+
from openpilot.system.hardware.hw import Paths
5+
6+
WATCHDOG_FN = f"{Paths.shm_path()}/wd_"
7+
_LAST_KICK = 0.0
8+
9+
def kick_watchdog():
10+
global _LAST_KICK
11+
current_time = time.monotonic()
12+
13+
if current_time - _LAST_KICK < 1.0:
14+
return
15+
16+
try:
17+
with open(f"{WATCHDOG_FN}{os.getpid()}", 'wb') as f:
18+
f.write(struct.pack('<Q', int(current_time * 1e9)))
19+
f.flush()
20+
_LAST_KICK = current_time
21+
except OSError:
22+
pass

selfdrive/ui/ui.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env python3
22
import pyray as rl
3+
from openpilot.common.watchdog import kick_watchdog
34
from openpilot.system.ui.lib.application import gui_app
45
from openpilot.selfdrive.ui.layouts.main import MainLayout
56
from openpilot.selfdrive.ui.ui_state import ui_state
67

78

9+
810
def main():
911
gui_app.init_window("UI")
1012
main_layout = MainLayout()
@@ -15,6 +17,8 @@ def main():
1517

1618
main_layout.render(rl.Rectangle(0, 0, gui_app.width, gui_app.height))
1719

20+
kick_watchdog()
21+
1822

1923
if __name__ == "__main__":
2024
main()

system/manager/process.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
from openpilot.common.basedir import BASEDIR
1717
from openpilot.common.params import Params
1818
from openpilot.common.swaglog import cloudlog
19-
from openpilot.system.hardware.hw import Paths
19+
from openpilot.common.watchdog import WATCHDOG_FN
2020

21-
WATCHDOG_FN = f"{Paths.shm_path()}/wd_"
2221
ENABLE_WATCHDOG = os.getenv("NO_WATCHDOG") is None
2322

2423

0 commit comments

Comments
 (0)