From e211b3afc43d87df2a71707e57c576e59ecc211c Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 24 Dec 2020 15:34:10 +0000 Subject: [PATCH] Clear up situation with nogui and carla-osc-gui script --- data/carla-osc-gui | 6 ++++-- source/frontend/carla_host.py | 18 ++++++++++-------- source/frontend/carla_shared.py | 19 +++++++++++++++---- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/data/carla-osc-gui b/data/carla-osc-gui index 60d379838..6e02c5a20 100755 --- a/data/carla-osc-gui +++ b/data/carla-osc-gui @@ -1,5 +1,7 @@ #!/bin/bash +set -e + PYTHON=$(which python3 2>/dev/null) if [ ! -f ${PYTHON} ]; then @@ -25,8 +27,8 @@ fi if lsof -i:21337 > /dev/null; then echo "NOTICE: Backend already running" else - echo "NOTICE: Backend not running yet, starting it now" - ${PYTHON} "${INSTALL_FRONTENDDIR}/carla" ${INSTALL_ARGS} --osc-gui=21337 "$@" & + ${PYTHON} "${INSTALL_FRONTENDDIR}/carla" ${INSTALL_ARGS} --osc-gui=21337 "$@" --with-appname="carla-osc-dsp" + echo "NOTICE: Backend was not running yet, start was triggered now" fi exec ${PYTHON} "${INSTALL_FRONTENDDIR}/carla-control" ${INSTALL_ARGS} osc.tcp://127.0.0.1:21337/Carla "$@" diff --git a/source/frontend/carla_host.py b/source/frontend/carla_host.py index 8ce72d50a..c4c5d66f2 100644 --- a/source/frontend/carla_host.py +++ b/source/frontend/carla_host.py @@ -3125,12 +3125,13 @@ def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = No # -------------------------------------------------------------------------------------------------------- # Print info - print("Carla %s started, status:" % VERSION) - print(" Python version: %s" % sys.version.split(" ",1)[0]) - print(" Qt version: %s" % QT_VERSION_STR) - print(" PyQt version: %s" % PYQT_VERSION_STR) - print(" Binary dir: %s" % pathBinaries) - print(" Resources dir: %s" % pathResources) + if not (gCarla.nogui and isinstance(gCarla.nogui, int)): + print("Carla %s started, status:" % VERSION) + print(" Python version: %s" % sys.version.split(" ",1)[0]) + print(" Qt version: %s" % QT_VERSION_STR) + print(" PyQt version: %s" % PYQT_VERSION_STR) + print(" Binary dir: %s" % pathBinaries) + print(" Resources dir: %s" % pathResources) # -------------------------------------------------------------------------------------------------------- # Init host @@ -3418,9 +3419,10 @@ def runHostWithoutUI(host): if not gCarla.nogui: return + projectFile = getInitialProjectFile(True) + if not isinstance(gCarla.nogui, int): oscPort = None - projectFile = getInitialProjectFile(True) if not projectFile: print("Carla no-gui mode can only be used together with a project file.") @@ -3442,7 +3444,7 @@ def runHostWithoutUI(host): print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error()) sys.exit(1) - if oscPort is None and not host.load_project(projectFile): + if projectFile and not host.load_project(projectFile): print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error()) host.engine_close() sys.exit(1) diff --git a/source/frontend/carla_shared.py b/source/frontend/carla_shared.py index 51a7c06de..83415547b 100644 --- a/source/frontend/carla_shared.py +++ b/source/frontend/carla_shared.py @@ -666,13 +666,18 @@ def handleInitialCommandLineArguments(file): print(" and OPTION can be one or more of the following:") print("") print(" --cnprefix\t Set a prefix for client names in multi-client mode.") - print(" --gdb \t Run Carla inside gdb.") - print(" -n,--no-gui \t Run Carla headless, don't show UI.") - print("") + if not isinstance(gCarla.nogui, int): + print(" --gdb \t Run Carla inside gdb.") + print(" -n,--no-gui \t Run Carla headless, don't show UI.") + print("") print(" -h,--help \t Print this help text and exit.") print(" -v,--version \t Print version information and exit.") print("") + if isinstance(gCarla.nogui, int): + print("NOTE: when using %s the FILE is only valid the first time the backend is started" % initName) + sys.exit(1) + sys.exit(0) elif arg in ("-v", "--v", "-version", "--version"): @@ -685,12 +690,18 @@ def handleInitialCommandLineArguments(file): print(" Binary dir: %s" % pathBinaries) print(" Resources dir: %s" % pathResources) - sys.exit(0) + sys.exit(1 if gCarla.nogui else 0) elif readPrefixNext: readPrefixNext = False gCarla.cnprefix = arg + if gCarla.nogui and isinstance(gCarla.nogui, int): + if os.fork(): + os._exit(0) + else: + os.setsid() + return (initName, libPrefix) # ------------------------------------------------------------------------------------------------------------