Skip to content

Commit

Permalink
Fixes spin_until_future_complete inside callback (#1316) (#1343)
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>
(cherry picked from commit 47346ef)

Co-authored-by: Jonathan <[email protected]>
  • Loading branch information
mergify[bot] and jmblixt3 authored Sep 6, 2024
1 parent 6a6e24b commit 2e0f6af
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 @@ -247,8 +247,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 2e0f6af

Please sign in to comment.