Skip to content

Commit aaf6a58

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

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)