Search code examples
rosrospy

Will actionlib.SimpleActionClient.cancel_all_goals block until completion?


Suppose I have the following:

action_client.cancel_all_goals()
print(action_client.get_status() != 'ACTIVE')

Is the above guaranteed to print True every time?

In other words, does SimpleActionClient.cancel_all_goals() cancel all goals before returning, or does it just send instructions to cancel goals without waiting for the goals to be really cancelled?


Solution

  • action_client.cancel_all_goals() just sends an instruction to cancel goals without waiting.

    Since the documentation of the method is not very helpful you need to have a look to action_client.h or action_client.py to find out whats happening.

    The code shows that to cancel all goals only a simple message is published (self.pub_cancel.publish(cancel_msg) or self.pub_cancel.publish(cancel_msg)). This means the call is asynchronous and will not block.

    This means your code

    action_client.cancel_all_goals()
    print(action_client.get_status() != 'ACTIVE')
    

    will typically print False but this is not guaranteed because:

    • The client could be already PREEMPTED, ABORTED, ... before
    • ROS is not deterministic, this means in theory the client could be cancelled between the calls of cancel_all_goals and get_status due to a thread switch.