Skip to content

Commit e1f4cb1

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 6cef575 commit e1f4cb1

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
@@ -219,11 +219,14 @@ def spin_once(
219219
:param timeout_sec: Seconds to wait. Block forever if ``None`` or negative. Don't wait if 0.
220220
"""
221221
executor = get_global_executor() if executor is None else executor
222+
node_was_added = False
222223
try:
223-
executor.add_node(node)
224+
225+
node_was_added = executor.add_node(node)
224226
executor.spin_once(timeout_sec=timeout_sec)
225227
finally:
226-
executor.remove_node(node)
228+
if node_was_added:
229+
executor.remove_node(node)
227230

228231

229232
def spin(node: 'Node', executor: Optional['Executor'] = None) -> None:

0 commit comments

Comments
 (0)