Python API mode: allow using an external CARLA server (e.g. Docker) without killing it

Open
#741 0 comments 0 reactions 0 assignees View on GitHub

@amateusr is already working on this.

Since Nov 3, 2026.

  • #742 by @amateusr — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
docker, python
Domain
backend

Research direction

Start with utils/environment.py, where the issue identifies launch_env() and close_ros_and_simulators() as the relevant entry points. Check how Python API mode handles CARLA shutdown and reads CARLA_ROOT; the proposed change should allow an externally managed server to remain running without requiring that variable. Verify the reported Docker reproduction and relevant environment-launch tests; an open linked pull request (#742) is already working on this issue.

Written by the indexing model from the issue text.

Description

Expected behavior
In Python API mode (ROS_VERSION=None), Behavior Metrics should be able to connect to a CARLA server that is already running and managed outside Behavior Metrics (for example in a Docker container), without stopping it and without requiring CARLA_ROOT.

Actual behavior
launch_env() calls close_ros_and_simulators(), which runs killall -9 CarlaUE4.sh and killall -9 CarlaUE4-Linux-Shipping. The CARLA processes inside a Docker container are visible from the host, so the container's server is killed. In addition, launch_env() reads os.environ["CARLA_ROOT"] unconditionally and fails with KeyError: 'CARLA_ROOT' even when CARLA is already running.

Steps to reproduce

  1. docker run -d --name carla-bm --gpus all --net=host carlasim/carla:0.9.15 ./CarlaUE4.sh -world-port=2000
  2. export ROS_VERSION=None (without CARLA_ROOT)
  3. python3 driver_carla.py -c configs/CARLA/default_carla_api.yml -g
  4. The CARLA server in the container is killed, then KeyError: 'CARLA_ROOT'.

Environment
Kubuntu 26.04.1 (Ubuntu base, X11 session), kernel 7.0, Intel i9-12900K, 32 GB RAM, NVIDIA RTX 5070 12 GB (driver 580.178.04), Python 3.10, CARLA 0.9.15 (carlasim/carla:0.9.15 Docker image), Behavior Metrics noetic-devel (dec1502), Python API mode.

Possible cause
close_ros_and_simulators() always kills CARLA, and CARLA_ROOT is read before checking whether CARLA is already running.

Possible solution
An opt-in environment variable BM_EXTERNAL_CARLA=1 that skips killing CARLA, and read CARLA_ROOT with os.environ.get() so it is only required when Behavior Metrics has to launch CARLA itself. I have a small patch ready (only utils/environment.py) and can open a PR, plus a documentation section for the install page.

Related: #672 (running CARLA on remote or cloud GPUs also benefits from an externally managed server).

Dominant language
Python
Stars
65
Forks
53
Avg merge
7m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JdeRobot/BehaviorMetrics

All issues in JdeRobot/BehaviorMetrics

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.