Callback groups — controlling which callbacks can run concurrently
Atlasbot · 17/8/2026 · 11 min read
default, every callback (subscriber, timer, service) in an ROS2 node belongs to the same group called MutuallyExclusiveCallbackGroup— which means that they never simultaneously run, even when the node uses MultiThreadedExecutor (see Multi-threading article) with multiple streams available. A slow-processing callback service (reading large files, calling network APIs) will prevent the callback from reading another sensor of the same node until done.
Key concepts
- MutuallyExclusiveCallbackGroup (default) — callbacks in the same group ensure never to run simultaneously, even with multiple free threads. Absolute security for shared data (no need to lock), but easy to block by a slow callback
- ReentrantCallbackGroup— callbacks in the same group are allowed to run parallel to each other, as long as the executor has enough thread. Must secure shared data (mutex) as race condition may now be present
from rclpy.callback_groups import MutuallyExclusiveCallbackGroup, ReentrantCallbackGroup
class MyNode(Node):
def __init__(self):
super().__init__("my_node")
fast_group = ReentrantCallbackGroup()
slow_group = MutuallyExclusiveCallbackGroup()
self.create_subscription(LaserScan, "/scan", self.scan_cb, 10,
callback_group=fast_group)
self.create_service(Trigger, "/save_map", self.save_map_cb,
callback_group=slow_group)
The above configuration completely separates two processing streams: scan_cb (sensor read, quick response needed) is in its own ReentrantCallbackGroup, which is never intercepted by save_map_cb (slow, few calls) by — because they belong to two different groups.
How it works
In summary: Callback in with the same group never runs parallel if it is Mutually exclusive, or can run parallel if it is Reentrant. Callback at two different groups can always run in parallel (if the executor is sufficiently threaded), regardless of the type of group.
Common mistake: changing Executor forgetting Callback Group — many people encounter callbacks "shocked" thinking single-threaded executors, switching to MultiThreadedExecutor but still seeing old phenomenon — reason: default all callbacks remain under the same MutuallyExclusiveCallbackGroup, changing executors does not automatically allow them to run parallel. MultiThreadedExecutor is only a necessary condition (having enough thread to run parallel), the proper Callback Group is a sufficient condition.
Technical details
Parameters
The full valence table of parallel capabilities, assuming the use of MultiThreadedExecutor with enough threads:
| Situation | Can we run it parallel? |
|---|---|
2 callbacks to the same 1 MutuallyExclusiveCallbackGroup | No |
2 callbacks to the same 1 ReentrantCallbackGroup | Yes |
| 2 callbacks in 2 different groups (of any kind) | Yes |
Use SingleThreadedExecutor (regardless of group type) | Never, because there's only one thread. |
Practical applications
Callback Group is the solution to the deadlock problem warned in the Service Communication article — when a node is both a subscriber and needs to call a service (including the service provided by the node itself or the associated node) within the callback: putting the callback subscriber and the service client into 2 different ReentrantCallbackGroup (combining MultiThreadedExecutor) allows them to run overlappingly on different streams, addressing the root problem of "node waiting for itself" — which is much more radical than just dodging by always calling call_async as temporarily recommended in that article.
Practical example
# BEFORE — latent deadlock: same group default (MutuallyExclusive)
class RiskyNode(Node):
def __init__(self):
super().__init__("risky_node")
self.client = self.create_client(Trigger, "/some_service")
self.create_subscription(String, "/trigger_topic", self.callback, 10)
def callback(self, msg):
future = self.client.call_async(Trigger.Request())
rclpy.spin_until_future_complete(self, future) # You can hang it!
# After — separate 2 callback groups, using MultiThreadedExecutor
class SafeNode(Node):
def __init__(self):
super().__init__("safe_node")
group_a = ReentrantCallbackGroup()
group_b = ReentrantCallbackGroup()
self.client = self.create_client(Trigger, "/some_service", callback_group=group_a)
self.create_subscription(String, "/trigger_topic", self.callback, 10,
callback_group=group_b)
With SafeNode, when callback (belonging to group_b) calls the service (handled by group_a), 2 different groups allow them to run on 2 separate threads of MultiThreadedExecutor— no longer in a "wait for yourself" situation as RiskyNode.
Common mistakes
- Changing the executor forgetting to separate the callback group— as stated in the Operating Principles section, this is the most common reason why the "shaking" phenomenon does not disappear despite switching to
MultiThreadedExecutor. - Using ReentrantCallbackGroup but not protecting shared data with mutex — allows multiple callback instances to run in parallel meaning race conditions may occur on shared data variable/structure — which need to manually add locks (mutex/lock) in place, ROS2 does not do this for you.
- Abusing ReentrantCallbackGroup for all callbacks — unnecessarily loses the "perfect safety, no locks" benefit of MutuallyExclusive — and should only be used for callbacks that actually need to run in parallel, not default for all.
- Misidentical non-transfer
callback_groupmeans that each automatic callback has its own group — default, non-specified callbackcallback_groupwill use default callback group of the node (typically 1 MutuallyExclusiveCallbackGroup) — which is not automatically separated as might be mistaken.
Conclusion
The Callback Group is an accurate tool to control which callbacks are allowed to run in parallel, which resolves the deadlock problem of nested service calls — but works only when properly combined with MultiThreadedExecutor. The core rule is that the same group, Mutually exclusive, can never be parallel, and the other group can always be parallel. The next article in the column is about Multi-threading — how the multi-threaded executor configuration that the Callback Group has just learned depends on.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.