Skip to content

Commit 837a9ed

Browse files
committed
use global
1 parent ec1d988 commit 837a9ed

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

common/watchdog.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44
from openpilot.system.hardware.hw import Paths
55

66
WATCHDOG_FN = f"{Paths.shm_path()}/wd_"
7-
7+
_LAST_KICK = 0.0
88

99
def kick_watchdog():
10+
global _LAST_KICK
1011
current_time = time.time()
11-
if not hasattr(kick_watchdog, 'last_kick'):
12-
kick_watchdog.last_kick = 0
1312

14-
if current_time - kick_watchdog.last_kick < 1.0:
13+
if current_time - _LAST_KICK < 1.0:
1514
return
1615

1716
try:
1817
with open(f"{WATCHDOG_FN}{os.getpid()}", 'wb') as f:
1918
f.write(struct.pack('<Q', int(current_time * 1e9)))
2019
f.flush()
21-
kick_watchdog.last_kick = current_time
20+
_LAST_KICK = current_time
2221
except OSError:
2322
pass

0 commit comments

Comments
 (0)