Skip to content

Commit

Permalink
Fixes spin_until_future_complete inside callback (#1316)
Browse files Browse the repository at this point in the history
Closes rclpy:#1313
Current if spin_unitl_future_complete is called inside a nodes callback it removes the node from the executor
This results in any subsiquent waitables to never be checked by the node since the node is no longer in the executor
This aims to fix that by only removing the node from the executor if it wasn't already present

Signed-off-by: Jonathan Blixt <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
jmblixt3 and mergify[bot] authored Aug 24, 2024
1 parent 59251fc commit 47346ef
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rclpy/rclpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ def spin_until_future_complete(
if ``None`` or negative. Don't wait if 0.
"""
executor = get_global_executor() if executor is None else executor
node_added = False
try:
executor.add_node(node)
node_added = executor.add_node(node)
executor.spin_until_future_complete(future, timeout_sec)
finally:
executor.remove_node(node)
if node_added:
executor.remove_node(node)

0 comments on commit 47346ef

Please sign in to comment.