Skip to content

Trajectory viewer

The web viewer server. See the Trajectory viewer guide.

start_viewer_server

start_viewer_server

start_viewer_server(host: str | None = None, port: int | None = None) -> ViewerServer

Start a trajectory viewer web server.

Parameters:

Name Type Description Default
host str | None

Host to bind to. Defaults to "localhost".

None
port int | None

Port to bind to. If None, a free port is chosen automatically.

None

Returns:

Type Description
ViewerServer

A ViewerServer handle.

Source code in caw/viewer/__init__.py
def start_viewer_server(
    host: str | None = None,
    port: int | None = None,
) -> ViewerServer:
    """Start a trajectory viewer web server.

    Args:
        host: Host to bind to.  Defaults to ``"localhost"``.
        port: Port to bind to.  If *None*, a free port is chosen automatically.

    Returns:
        A `ViewerServer` handle.
    """
    host = host or "localhost"
    port = port or _find_free_port()

    httpd = _ThreadedHTTPServer((host, port), _Handler)

    thread = threading.Thread(target=httpd.serve_forever, daemon=True)
    thread.start()

    return ViewerServer(httpd, thread, host, port)

ViewerServer

ViewerServer

ViewerServer(httpd: HTTPServer, thread: Thread, host: str, port: int)

Handle for a running trajectory viewer server.

Source code in caw/viewer/__init__.py
def __init__(
    self,
    httpd: HTTPServer,
    thread: threading.Thread,
    host: str,
    port: int,
) -> None:
    self._httpd = httpd
    self._thread = thread
    self.host = host
    self.port = port

check_status

check_status() -> bool

Return True if the server is running.

Source code in caw/viewer/__init__.py
def check_status(self) -> bool:
    """Return True if the server is running."""
    return self._thread.is_alive()

stop

stop() -> None

Shut down the server.

Source code in caw/viewer/__init__.py
def stop(self) -> None:
    """Shut down the server."""
    self._httpd.shutdown()
    self._thread.join(timeout=5)