This commit is contained in:
Comma Device
2024-06-17 17:10:43 +00:00
parent 7f182b7fae
commit 75c91213a2

View File

@@ -19,7 +19,7 @@ from openpilot.common.swaglog import cloudlog
WATCHDOG_FN = "/dev/shm/wd_" WATCHDOG_FN = "/dev/shm/wd_"
ENABLE_WATCHDOG = os.getenv("NO_WATCHDOG") is None ENABLE_WATCHDOG = os.getenv("NO_WATCHDOG") is None
ENABLE_WATCHDOG = False # Fixme
_log_dir = "" _log_dir = ""
def nativelauncher(pargs: list[str], cwd: str, name: str, log_path: str) -> None: def nativelauncher(pargs: list[str], cwd: str, name: str, log_path: str) -> None:
@@ -34,35 +34,23 @@ def nativelauncher(pargs: list[str], cwd: str, name: str, log_path: str) -> None
proc.wait() proc.wait()
def launcher(proc: str, name: str, log_path: str) -> None: def launcher(proc: str, name: str, log_path: str) -> None:
while True: for _ in iter(int, 1):
try: try:
# Initialize the module and setup the process title and logging mod = importlib.import_module(proc)
mod = importlib.import_module(proc) setproctitle(proc)
setproctitle(name) messaging.context = messaging.Context()
messaging.context = messaging.Context() cloudlog.bind(daemon=name)
cloudlog.bind(daemon=name) sentry.set_tag("daemon", name)
sentry.set_tag("daemon", name) with open(log_path, 'a') as log_file, subprocess.Popen(['python', '-m', proc], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) as proc:
log_file.write("Started "+name)
# Command to run the process for line in proc.stdout:
command = ['python', '-m', proc] print(line, end='')
log_file.write(line)
# Open the log file and start the subprocess proc.wait()
with open(log_path, 'a') as log_file, subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) as proc_instance: except Exception as e:
log_file.write(f"Started {name}\n") print ("Fatal: "+name)
print (e)
# Process the output from the subprocess sentry.capture_exception()
for line in iter(proc_instance.stdout.readline, ''):
print(line, end='')
log_file.write(line)
# Wait for the subprocess to terminate
proc_instance.wait()
except Exception as e:
# Log the error and restart the process after logging the exception
print(f"Fatal: {name}")
print(e)
sentry.capture_exception()
def join_process(process: Process, timeout: float) -> None: def join_process(process: Process, timeout: float) -> None:
t = time.monotonic() t = time.monotonic()