Skip to content

Commit 7f768b2

Browse files
[rclpy] Fix spin() incorrectly removing node from executor if already attached (#1446) (#1451)
(cherry picked from commit 3414456) Signed-off-by: Alon <[email protected]> Co-authored-by: Alon Borenshtein <[email protected]>
1 parent 9c3e966 commit 7f768b2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

rclpy/rclpy/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,14 @@ def spin_once(node: 'Node', *, executor: 'Executor' = None, timeout_sec: float =
201201
:param timeout_sec: Seconds to wait. Block forever if ``None`` or negative. Don't wait if 0.
202202
"""
203203
executor = get_global_executor() if executor is None else executor
204+
node_was_added = False
204205
try:
205-
executor.add_node(node)
206+
207+
node_was_added = executor.add_node(node)
206208
executor.spin_once(timeout_sec=timeout_sec)
207209
finally:
208-
executor.remove_node(node)
210+
if node_was_added:
211+
executor.remove_node(node)
209212

210213

211214
def spin(node: 'Node', executor: 'Executor' = None) -> None:

0 commit comments

Comments
 (0)