manager: write power monitor flag atomically (#36734)

This commit is contained in:
Adeeb Shihadeh
2025-11-30 15:14:31 -08:00
committed by GitHub
parent 7521fd11e2
commit 436e3dec3e
2 changed files with 3 additions and 2 deletions

View File

@@ -33,7 +33,7 @@ class CallbackReader:
@contextlib.contextmanager
def atomic_write(path: str, mode: str = 'w', buffering: int = -1, encoding: str | None = None, newline: str | None = None,
overwrite: bool = False):
overwrite: bool = False):
"""Write to a file atomically using a temporary file in the same directory as the destination file."""
dir_name = os.path.dirname(path)

View File

@@ -9,6 +9,7 @@ import traceback
from cereal import log
import cereal.messaging as messaging
import openpilot.system.sentry as sentry
from openpilot.common.utils import atomic_write
from openpilot.common.params import Params, ParamKeyFlag
from openpilot.common.text_window import TextWindow
from openpilot.system.hardware import HARDWARE
@@ -162,7 +163,7 @@ def manager_thread() -> None:
# kick AGNOS power monitoring watchdog
try:
if sm.all_checks(['deviceState']):
with open("/var/tmp/power_watchdog", "w") as f:
with atomic_write("/var/tmp/power_watchdog", "w", overwrite=True) as f:
f.write(str(time.monotonic()))
except Exception:
pass