[rclpy] Fix spin_once() removing node from executor even if already attached (backport #1446) #1450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request fixes a bug where
rclpy.spin_once()would remove a node from its executor that it didn't add.Previously,
spin_once()unconditionally calledexecutor.remove_node(node)at the end, disconnecting nodes managed by user-created executors (e.g.,MultiThreadedExecutor).This fix tracks whether
spin_once()itself added the node, and only removes it if necessary — matching the behavior already used inspin_until_future_complete().Motivation
Calling
rclpy.spin_once()on a node that is part of an existing executor (e.g., for asynchronous callbacks) currently breaks the executor's management, causing nodes to silently stop working.This fix ensures better safety and makes
rclpyutilities more consistent.Related Issue
It handles a similar issue like #1316
This is an automatic backport of pull request #1446 done by [Mergify](https://mergify.com).