Skip to content

sim2bot.Robot.close

close() -> None

Close control, telemetry, camera, and UDP resources.

Active camera feeds are unsubscribed first. Calling close() more than once is safe.

Returns:

  • None

    The method is safe to call repeatedly.

Source code in sim2bot/client.py
def close(self) -> None:
    """Close control, telemetry, camera, and UDP resources.

    Active camera feeds are unsubscribed first. Calling ``close()`` more than
    once is safe.

    Returns:
        The method is safe to call repeatedly.
    """
    self._stop.set()
    with self._cameras_lock:
        camera_ids = list(self._cameras.keys())
    for camera_id in camera_ids:
        self._unsubscribe(camera_id)
    for conn in (self._conn, self._video_conn, self._udp_sock):
        if conn is not None:
            try:
                conn.close()
            except Exception:
                pass
    self._conn = None
    self._video_conn = None
    self._udp_sock = None

Practical examples

Examples use objects discovered from the current scene rather than hard-coded robot metadata.

Always close with finally

sim = Robot(auto_bridge=True).connect()
try:
    sim.move_to(sim.describe()[0].home)
finally:
    sim.close()

Close an active camera feed

sim = Robot(auto_bridge=True).connect()
feed = sim.camera(sim.cameras()[0]["id"])
feed.close()
sim.close()

Guidance

Usage tip

It is safe to call close() more than once during cleanup.


See also