Execution and Callbacks
There are two components that control the execution of callbacks: executors and callback groups.
Executors are responsible for the actual execution of callbacks and should extend the Executor
class.
Callback groups are used to enforce concurrency rules for callbacks and should extend the CallbackGroup
class.
Executors
Callback Groups
- class rclpy.callback_groups.CallbackGroup
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()
, andending_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
thenCallbackGroup.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
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
thenCallbackGroup.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
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
thenCallbackGroup.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.