Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Client Stop Recorder

From Leeroopedia
Knowledge Sources
Domains Simulation, Recording
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for stopping an active recording session and finalizing the binary log file provided by the CARLA simulator.

Description

The Client.stop_recorder method instructs the CARLA server to terminate the active recording session. It flushes any buffered frame data to disk, writes final metadata to the recording file, and closes the file handle. After this call returns, the recording file is complete and ready for replay or inspection.

This method takes no arguments and returns no value. It is a synchronous call that blocks until the finalization process is complete. If no recording session is active, calling this method has no effect and does not produce an error.

It is important to always call stop_recorder after a recording session, especially before loading a new map, starting a new recording, or disconnecting from the server. Failing to do so may result in an incomplete or corrupted recording file.

Usage

Call this method when the simulation scenario you are recording has completed. It should be invoked after the simulation loop has finished but before cleaning up actors or disconnecting from the server. In automated pipelines, include it in a finally block or cleanup handler to ensure recordings are always properly finalized even if the scenario encounters an error.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/carla/src/Client.cpp:L205, LibCarla/source/carla/client/Client.h:L125-127

Signature

Client.stop_recorder() -> None

Import

import carla

I/O Contract

Inputs

Name Type Required Description
(none) -- -- This method takes no parameters.

Outputs

Name Type Description
return None No return value. The method blocks until the recording file is finalized.

Usage Examples

Basic Example

import carla

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()

# Start recording
client.start_recorder("test_recording.log")

# Run some simulation ticks
for _ in range(200):
    world.tick()

# Stop recording -- finalizes the file
client.stop_recorder()
print("Recording saved successfully")

Safe Recording with Error Handling

import carla

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()

vehicles = []

try:
    # Start recording
    client.start_recorder("scenario_with_error_handling.log", additional_data=True)

    # Spawn actors
    blueprint_library = world.get_blueprint_library()
    spawn_points = world.get_map().get_spawn_points()

    for i in range(10):
        bp = blueprint_library.filter('vehicle.*')[i % 5]
        vehicle = world.try_spawn_actor(bp, spawn_points[i])
        if vehicle:
            vehicle.set_autopilot(True)
            vehicles.append(vehicle)

    # Run simulation
    for tick in range(500):
        world.tick()
        # Scenario logic that might raise an exception
        if tick == 300:
            raise RuntimeError("Simulated scenario error")

except Exception as e:
    print(f"Scenario encountered an error: {e}")

finally:
    # Always stop recording, even if an error occurred
    client.stop_recorder()
    print("Recording finalized")

    # Clean up actors
    for v in vehicles:
        v.destroy()

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment