mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-07 22:52:06 +08:00
Memory Hither
This commit is contained in:
@@ -33,14 +33,12 @@ def python_ui_enabled(device_type: str) -> bool:
|
||||
return device_type not in ("tici", "tizi")
|
||||
|
||||
|
||||
def python_process_start_method(uses_python_ui: bool, is_pc: bool = PC) -> str:
|
||||
# Native/QT UI devices rely on fork copy-on-write to keep onroad memory low.
|
||||
# Python/raylib UI uses subprocess to avoid fork/import-lock boot hangs.
|
||||
def python_ui_process_start_method(uses_python_ui: bool, is_pc: bool = PC) -> str:
|
||||
return "fork" if is_pc or not uses_python_ui else "subprocess"
|
||||
|
||||
|
||||
PYTHON_UI = python_ui_enabled(device_type)
|
||||
os.environ.setdefault("PYTHON_PROCESS_START_METHOD", python_process_start_method(PYTHON_UI))
|
||||
PYTHON_UI_PROCESS_START_METHOD = python_ui_process_start_method(PYTHON_UI)
|
||||
|
||||
from openpilot.system.manager.process import PythonProcess, NativeProcess, DaemonProcess
|
||||
|
||||
@@ -176,7 +174,13 @@ procs += [
|
||||
]
|
||||
|
||||
if PYTHON_UI:
|
||||
procs.append(PythonProcess("ui", "selfdrive.ui.ui", always_run, watchdog_max_dt=UI_WATCHDOG_MAX_DT))
|
||||
procs.append(PythonProcess(
|
||||
"ui",
|
||||
"selfdrive.ui.ui",
|
||||
always_run,
|
||||
watchdog_max_dt=UI_WATCHDOG_MAX_DT,
|
||||
start_method=PYTHON_UI_PROCESS_START_METHOD,
|
||||
))
|
||||
else:
|
||||
procs.append(NativeProcess("ui", "selfdrive/ui", ["./ui"], always_run, watchdog_max_dt=UI_WATCHDOG_MAX_DT))
|
||||
|
||||
|
||||
@@ -9,7 +9,13 @@ from cereal import car
|
||||
from openpilot.common.params import Params, ParamKeyFlag
|
||||
import openpilot.system.manager.manager as manager
|
||||
from openpilot.system.manager.process import ensure_running
|
||||
from openpilot.system.manager.process_config import managed_processes, procs, python_process_start_method, python_ui_enabled
|
||||
from openpilot.system.manager.process import PythonProcess
|
||||
from openpilot.system.manager.process_config import (
|
||||
managed_processes,
|
||||
procs,
|
||||
python_ui_enabled,
|
||||
python_ui_process_start_method,
|
||||
)
|
||||
from openpilot.system.hardware import HARDWARE
|
||||
|
||||
os.environ['FAKEUPLOAD'] = "1"
|
||||
@@ -111,10 +117,21 @@ class TestManager:
|
||||
assert names.index("the_galaxy") < ui_idx
|
||||
assert names.index("galaxy") < ui_idx
|
||||
|
||||
def test_python_process_start_method_follows_ui_implementation(self):
|
||||
assert python_process_start_method(False, False) == "fork"
|
||||
assert python_process_start_method(True, False) == "subprocess"
|
||||
assert python_process_start_method(True, True) == "fork"
|
||||
def test_python_ui_process_start_method_follows_ui_implementation(self):
|
||||
assert python_ui_process_start_method(False, False) == "fork"
|
||||
assert python_ui_process_start_method(True, False) == "subprocess"
|
||||
assert python_ui_process_start_method(True, True) == "fork"
|
||||
|
||||
def test_python_ui_subprocess_is_scoped_to_ui(self):
|
||||
ui_proc = managed_processes["ui"]
|
||||
uses_python_ui = python_ui_enabled(HARDWARE.get_device_type())
|
||||
|
||||
assert isinstance(ui_proc, PythonProcess) == uses_python_ui
|
||||
if uses_python_ui:
|
||||
assert ui_proc.start_method == python_ui_process_start_method(uses_python_ui)
|
||||
for proc in procs:
|
||||
if isinstance(proc, PythonProcess) and proc.name != "ui":
|
||||
assert proc.start_method is None
|
||||
|
||||
def test_python_ui_env_override(self, monkeypatch):
|
||||
monkeypatch.setenv("USE_RAYLIB_UI", "1")
|
||||
|
||||
Reference in New Issue
Block a user