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) None

Add an entity to the callback group.

Parameters:

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

beginning_execution(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) 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) None

Notify group that a callback has finished executing.

Parameters:

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

has_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)

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)

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)

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)

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)

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)

Notify group that a callback has finished executing.

Parameters:

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