rclpy.callback_groups module

class rclpy.callback_groups.CallbackGroup

Bases: object

The base class for a callback group.

A callback group controls when callbacks are allowed to be executed.

This class should not be instantiated. Instead, classes should extend it and implement can_execute(), beginning_execution(), and ending_execution().

add_entity(entity: Entity) None

Add an entity to the callback group.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

beginning_execution(entity: Entity) bool

Get permission for the callback from the group to begin executing an entity.

If this returns True then CallbackGroup.ending_execution() must be called after the callback has been executed.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

Returns:

True if the callback can be executed, False otherwise.

can_execute(entity: Entity) bool

Determine if an entity can be executed.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

Returns:

True if the entity can be executed, False otherwise.

ending_execution(entity: Entity) None

Notify group that a callback has finished executing.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

has_entity(entity: Entity) bool

Determine if an entity has been added to this group.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

class rclpy.callback_groups.MutuallyExclusiveCallbackGroup

Bases: CallbackGroup

Allow only one callback to be executing at a time.

beginning_execution(entity: Entity) bool

Get permission for the callback from the group to begin executing an entity.

If this returns True then CallbackGroup.ending_execution() must be called after the callback has been executed.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

Returns:

True if the callback can be executed, False otherwise.

can_execute(entity: Entity) bool

Determine if an entity can be executed.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

Returns:

True if the entity can be executed, False otherwise.

ending_execution(entity: Entity) None

Notify group that a callback has finished executing.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

class rclpy.callback_groups.ReentrantCallbackGroup

Bases: CallbackGroup

Allow callbacks to be executed in parallel without restriction.

beginning_execution(entity: Entity) Literal[True]

Get permission for the callback from the group to begin executing an entity.

If this returns True then CallbackGroup.ending_execution() must be called after the callback has been executed.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

Returns:

True if the callback can be executed, False otherwise.

can_execute(entity: Entity) Literal[True]

Determine if an entity can be executed.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.

Returns:

True if the entity can be executed, False otherwise.

ending_execution(entity: Entity) None

Notify group that a callback has finished executing.

Parameters:

entity – a subscription, timer, client, service, or waitable instance.