From 94270e77252b9d4a2e9e1f9951b8447354fa4ca0 Mon Sep 17 00:00:00 2001 From: Henrik Muehe Date: Sun, 3 May 2026 14:04:30 +0200 Subject: [PATCH] Planner: lazy-load camotics.gplan so HTTP listener comes up first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Importing camotics.gplan pulls in a C++ extension (libstdc++, boost::python, etc.) which adds several seconds to bbctrl startup on the Pi. Defer it to Planner.init() — bbctrl can serve the UI and accept connections without ever touching the planner, and the penalty is paid only the first time motion is queued. --- src/py/bbctrl/Planner.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/py/bbctrl/Planner.py b/src/py/bbctrl/Planner.py index fe27066..c967611 100644 --- a/src/py/bbctrl/Planner.py +++ b/src/py/bbctrl/Planner.py @@ -30,7 +30,22 @@ import math import re import time from collections import deque -import camotics.gplan as gplan # pylint: disable=no-name-in-module,import-error +# camotics.gplan is heavy (loads a C++ extension that pulls in libstdc++, +# boost::python, etc.). Defer it: bbctrl can listen on HTTP and serve +# the UI without ever touching the planner. Lazy-load the first time +# Planner.init() runs, which is when the user actually queues motion. +gplan = None +def _load_gplan(): + global gplan + if gplan is None: + try: + import bbctrl.Trace as _T + with _T.span('imports.camotics_gplan'): + import camotics.gplan as _gplan # pylint: disable=no-name-in-module,import-error + except Exception: + import camotics.gplan as _gplan # pylint: disable=no-name-in-module,import-error + gplan = _gplan + return gplan import bbctrl.Cmd as Cmd from bbctrl.CommandQueue import CommandQueue @@ -329,7 +344,7 @@ class Planner(): if stop: self.ctrl.mach.stop() - self.planner = gplan.Planner() + self.planner = _load_gplan().Planner() self.planner.set_resolver(self._get_var_cb) # TODO logger is global and will not work correctly in demo mode self.planner.set_logger(self._log_cb, 1, 'LinePlanner:3')