Skip to content

sim2bot.is_bridge_running

is_bridge_running(url: str = DEFAULT_CONTROL_URL, timeout: float = 0.5) -> bool

Check whether the bridge health endpoint responds successfully.

Parameters:

  • url (str, default: DEFAULT_CONTROL_URL ) –

    Bridge control WebSocket URL used to derive the health URL.

  • timeout (float, default: 0.5 ) –

    HTTP timeout in seconds.

Returns:

  • bool

    True only when the endpoint responds with HTTP 200.

Source code in sim2bot/bridge.py
def is_bridge_running(url: str = DEFAULT_CONTROL_URL, timeout: float = 0.5) -> bool:
    """Check whether the bridge health endpoint responds successfully.

    Args:
        url: Bridge control WebSocket URL used to derive the health URL.
        timeout: HTTP timeout in seconds.

    Returns:
        ``True`` only when the endpoint responds with HTTP 200.
    """
    try:
        with urllib.request.urlopen(health_url(url), timeout=timeout) as response:
            return response.status == 200
    except (OSError, urllib.error.URLError):
        return False

Practical examples

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

Check the default bridge

from sim2bot import is_bridge_running

if not is_bridge_running():
    print("Bridge is offline")

Check a custom endpoint

ready = is_bridge_running(
    "ws://127.0.0.1:9000/ws",
    timeout=1.0,
)

Guidance

Usage tip

This checks bridge health only; it does not prove that a browser simulator is connected.


See also