Context

class rclpy.context.Context

Encapsulates the lifecycle of init and shutdown.

Context objects should not be reused, and are finalized in their destructor. Wraps the rcl_context_t type.

Example:
>>> from rclpy.context import Context
>>> with Context() as context:
>>>     context.ok()
True
destroy() None
get_domain_id() int

Get domain id of context.

property handle: ContextHandle | None
init(args: List[str] | None = None, *, initialize_logging: bool = True, domain_id: int | None = None) None

Initialize ROS communications for a given context.

Parameters:

args – List of command line arguments.

ok() bool

Check if context hasn’t been shut down.

on_shutdown(callback: Callable[[], None]) None

Add a callback to be called on shutdown.

shutdown() None

Shutdown this context.

try_shutdown() None

Shutdown this context, if not already shutdown.

class rclpy.context.ContextHandle(*args, **kwargs)
get_domain_id() int
ok() bool
shutdown() None