From b0c739a45d50bd1578c87ef7f985cd8dce1ce386 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Wed, 13 Feb 2019 15:54:05 -0800 Subject: [PATCH] Remove race from server_single_goal example Signed-off-by: Jacob Perron --- .../server_single_goal.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rclpy/actions/minimal_action_server/examples_rclpy_minimal_action_server/server_single_goal.py b/rclpy/actions/minimal_action_server/examples_rclpy_minimal_action_server/server_single_goal.py index a4d80d19..de164a57 100644 --- a/rclpy/actions/minimal_action_server/examples_rclpy_minimal_action_server/server_single_goal.py +++ b/rclpy/actions/minimal_action_server/examples_rclpy_minimal_action_server/server_single_goal.py @@ -37,6 +37,7 @@ def __init__(self): 'fibonacci', execute_callback=self.execute_callback, goal_callback=self.goal_callback, + handle_accepted_callback=self.handle_accepted_callback, cancel_callback=self.cancel_callback, callback_group=ReentrantCallbackGroup()) @@ -47,14 +48,18 @@ def destroy(self): def goal_callback(self, goal_request): """Accepts or rejects a client request to begin an action.""" self.get_logger().info('Received goal request') + return GoalResponse.ACCEPT + + def handle_accepted_callback(self, goal_handle): with self._goal_lock: # This server only allows one goal at a time if self._goal_handle is not None and self._goal_handle.is_active: self.get_logger().info('Aborting previous goal') # Abort the existing goal self._goal_handle.set_aborted() + self._goal_handle = goal_handle - return GoalResponse.ACCEPT + goal_handle.execute() def cancel_callback(self, goal): """Accepts or rejects a client request to cancel an action.""" @@ -64,8 +69,6 @@ def cancel_callback(self, goal): def execute_callback(self, goal_handle): """Executes the goal.""" self.get_logger().info('Executing goal...') - with self._goal_lock: - self._goal_handle = goal_handle # Append the seeds for the Fibonacci sequence feedback_msg = Fibonacci.Feedback()