Kill rosbag with system() command inside another node
I'm trying to gracefully kill a rosbag
node created with rosbag record -a -O my_bag_name.bag __name:=my_rosbag_node
by invoking system("rosnode kill /my_rosbag_node")
from another node (let's call it node_x).
It appears to work since the terminal tab in which rosbag
is running shows the following output:
Output_1:
[ WARN] [1646657025.635004612]: Shutdown request received.
[ WARN] [1646657025.635071515]: Reason given for shutdown: [user request]
However, in the terminal tab in which the nodex is running (nodex has been launched from roslaunch
) there's the following output:
Output_2:
killing /all_topics_bag
killed
ERROR: Unknown node(s):
* /all_topics_bag
Output1 and Output2 are shown in the same instant.
On one hand it seems that rosbag
has been killed successfully, on the other hand someone (roscore, roslaunch? I'm pretty sure it's not my nodex) seems to try to contact `/alltopics_bag` and since the node has been already killed it returns an error.
Should I invoke system() with some special arguments?
Or is there a better way to get the same result that I'd like to get?
Asked by 0novanta on 2022-03-07 08:25:26 UTC
Answers
I had this issue before. What is happened is that rosnode kill
uses XMLRPC call to shutdown the node and it would skip the normal shutdown process by SIGINT. This will lead to uncertainty of whether node is successfully killed. It is highlighted in the man page here "IMPORTANT: rosnode kill is not guaranteed to succeed. If a node is hung or set to "respawn" in roslaunch, it may either fail to die or may quickly reappear."
In your case, you node is killed as output_1 shows. If you want to check the result, you can use rosnode cleanup
and it will remove the node killed from the list. After that node_x will know the state of my_rosbag_node for sure and the error should be removed.
Asked by victorlu on 2022-04-25 21:02:53 UTC
Comments
Thank you! I will try this and keep you posted.
Asked by 0novanta on 2022-05-02 02:24:13 UTC
Comments