Cleaning up after shutdown request
In my node looping portion, I check for shutdown using ros::isShuttingDown()
. After the looping portion, I wish to perform a couple of actions before shutdown. The reason for this is that I am attempting to programatically start and stop nodes. The node is being stopped either with CTRL-C
or rosnode kill
However, this doesn't seem to function as I hope.
Here is a sample of my code:
while(!ros::isShuttingDown()){
//while(ros::ok()) { // Does not work either.
ros::spinOnce();
rate.sleep();
}
//EDIT:
ROS_INFO("will not print");
fflush(stdout);
//FIXME Cleanup section not running
// Cleanup
localizer.nh.setParam(
strcat(strcat(strcpy(localizer_node_param, "/"),
LOCALIZER_NODE),"_running"), false);
return SUCCESS;
In this instance, the parameter is not re-set at the end of life of this node. Can someone reproduce this behavior? Simple loop and ROS_INFO() statement is sufficient.
EDIT: ROS log statements also do not print to stdout when placed as shown (with or without fflush(stdout);
)
I am not fully aware of how the shutdown is implemented. But it could be in the process of shutting down, the parameter cannot be written to the parameter server, due to the shutdown itself...
See edit. ROS log statements don't print out either. I get the sense that the code after the looping portion does not run.