Start ui before manager preimport (#20468)
* start ui early
* test sets this afer import
old-commit-hash: 261045668b
This commit is contained in:
parent
30f036680b
commit
5c08699614
|
@ -14,7 +14,7 @@ from selfdrive.swaglog import add_logentries_handler, cloudlog
|
|||
from selfdrive.version import dirty
|
||||
|
||||
TOTAL_SCONS_NODES = 1225
|
||||
MAX_BUILD_PROGRESS = 70
|
||||
MAX_BUILD_PROGRESS = 100
|
||||
PREBUILT = os.path.exists(os.path.join(BASEDIR, 'prebuilt'))
|
||||
|
||||
|
||||
|
|
|
@ -10,10 +10,8 @@ import cereal.messaging as messaging
|
|||
import selfdrive.crash as crash
|
||||
from common.basedir import BASEDIR
|
||||
from common.params import Params
|
||||
from common.spinner import Spinner
|
||||
from common.text_window import TextWindow
|
||||
from selfdrive.hardware import HARDWARE
|
||||
from selfdrive.manager.build import MAX_BUILD_PROGRESS, PREBUILT
|
||||
from selfdrive.manager.helpers import unblock_stdout
|
||||
from selfdrive.manager.process import ensure_running
|
||||
from selfdrive.manager.process_config import managed_processes
|
||||
|
@ -22,7 +20,7 @@ from selfdrive.swaglog import add_logentries_handler, cloudlog
|
|||
from selfdrive.version import dirty, version
|
||||
|
||||
|
||||
def manager_init(spinner=None):
|
||||
def manager_init():
|
||||
params = Params()
|
||||
params.manager_start()
|
||||
|
||||
|
@ -69,7 +67,7 @@ def manager_init(spinner=None):
|
|||
print("WARNING: failed to make /dev/shm")
|
||||
|
||||
# set dongle id
|
||||
reg_res = register(spinner)
|
||||
reg_res = register(show_spinner=True)
|
||||
if reg_res:
|
||||
dongle_id = reg_res
|
||||
else:
|
||||
|
@ -85,16 +83,9 @@ def manager_init(spinner=None):
|
|||
crash.bind_extra(version=version, dirty=dirty, device=HARDWARE.get_device_type())
|
||||
|
||||
|
||||
def manager_prepare(spinner=None):
|
||||
# build all processes
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
total = 100.0 - (0 if PREBUILT else MAX_BUILD_PROGRESS)
|
||||
for i, p in enumerate(managed_processes.values()):
|
||||
def manager_prepare():
|
||||
for p in managed_processes.values():
|
||||
p.prepare()
|
||||
if spinner:
|
||||
perc = (100.0 - total) + total * (i + 1) / len(managed_processes)
|
||||
spinner.update_progress(perc, 100.)
|
||||
|
||||
|
||||
def manager_cleanup():
|
||||
|
@ -104,7 +95,7 @@ def manager_cleanup():
|
|||
cloudlog.info("everything is dead")
|
||||
|
||||
|
||||
def manager_thread(spinner=None):
|
||||
def manager_thread():
|
||||
cloudlog.info("manager start")
|
||||
cloudlog.info({"environ": os.environ})
|
||||
|
||||
|
@ -118,8 +109,6 @@ def manager_thread(spinner=None):
|
|||
ignore += os.getenv("BLOCK").split(",")
|
||||
|
||||
ensure_running(managed_processes.values(), started=False, not_run=ignore)
|
||||
if spinner: # close spinner when ui has started
|
||||
spinner.close()
|
||||
|
||||
started_prev = False
|
||||
params = Params()
|
||||
|
@ -158,18 +147,25 @@ def manager_thread(spinner=None):
|
|||
break
|
||||
|
||||
|
||||
def main(spinner=None):
|
||||
manager_init(spinner)
|
||||
manager_prepare(spinner)
|
||||
def main():
|
||||
prepare_only = os.getenv("PREPAREONLY") is not None
|
||||
|
||||
if os.getenv("PREPAREONLY") is not None:
|
||||
manager_init()
|
||||
|
||||
# Start ui early so prepare can happen in the background
|
||||
if not prepare_only:
|
||||
managed_processes['ui'].start()
|
||||
|
||||
manager_prepare()
|
||||
|
||||
if prepare_only:
|
||||
return
|
||||
|
||||
# SystemExit on sigterm
|
||||
signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(1))
|
||||
|
||||
try:
|
||||
manager_thread(spinner)
|
||||
manager_thread()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
crash.capture_exception()
|
||||
|
@ -183,11 +179,9 @@ def main(spinner=None):
|
|||
|
||||
if __name__ == "__main__":
|
||||
unblock_stdout()
|
||||
spinner = Spinner()
|
||||
spinner.update_progress(MAX_BUILD_PROGRESS, 100)
|
||||
|
||||
try:
|
||||
main(spinner)
|
||||
main()
|
||||
except Exception:
|
||||
add_logentries_handler(cloudlog)
|
||||
cloudlog.exception("Manager failed to start")
|
||||
|
@ -195,7 +189,6 @@ if __name__ == "__main__":
|
|||
# Show last 3 lines of traceback
|
||||
error = traceback.format_exc(-3)
|
||||
error = "Manager failed to start\n\n" + error
|
||||
spinner.close()
|
||||
with TextWindow(error) as t:
|
||||
t.wait_for_exit()
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import jwt
|
|||
from datetime import datetime, timedelta
|
||||
from common.api import api_get
|
||||
from common.params import Params
|
||||
from common.spinner import Spinner
|
||||
from common.file_helpers import mkdirs_exists_ok
|
||||
from common.basedir import PERSIST
|
||||
from selfdrive.hardware import HARDWARE
|
||||
|
@ -15,7 +16,7 @@ from selfdrive.version import version, terms_version, training_version, get_git_
|
|||
get_git_branch, get_git_remote
|
||||
|
||||
|
||||
def register(spinner=None):
|
||||
def register(show_spinner=False):
|
||||
params = Params()
|
||||
params.put("Version", version)
|
||||
params.put("TermsVersion", terms_version)
|
||||
|
@ -51,7 +52,8 @@ def register(spinner=None):
|
|||
needs_registration = needs_registration or dongle_id is None
|
||||
|
||||
if needs_registration:
|
||||
if spinner is not None:
|
||||
if show_spinner:
|
||||
spinner = Spinner()
|
||||
spinner.update("registering device")
|
||||
|
||||
# Create registration token, in the future, this key will make JWTs directly
|
||||
|
@ -85,7 +87,11 @@ def register(spinner=None):
|
|||
cloudlog.exception("failed to authenticate")
|
||||
time.sleep(1)
|
||||
|
||||
if show_spinner:
|
||||
spinner.close()
|
||||
|
||||
return dongle_id
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(register())
|
||||
|
|
Loading…
Reference in New Issue