From 2e0f6af120ce337fa9bcbf21a5ebb4d7a73cba88 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:23:00 +0200 Subject: [PATCH] Fixes spin_until_future_complete inside callback (#1316) (#1343) 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 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 47346ef9688039b890ae19c499d4b51587a7305b) Co-authored-by: Jonathan --- rclpy/rclpy/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rclpy/rclpy/__init__.py b/rclpy/rclpy/__init__.py index 48db53da0..89e97240c 100644 --- a/rclpy/rclpy/__init__.py +++ b/rclpy/rclpy/__init__.py @@ -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)