ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

How to perform an action at nodelet unload / shutdown?

asked 2012-05-29 05:30:51 -0600

ipso gravatar image

updated 2012-05-29 05:40:57 -0600

I'm trying to print / publish some statistics / diagnostic info at the time of nodelet unloading / exit. According to this answer on ros-users by Josh Faust the destructor of the nodelet should be used for this.

The problem I'm experiencing is that the text is sometimes printed, sometimes not at all and sometimes I get:

...
[my_nodelet_mgr-2] killing on exit
pure virtual method called
terminate called without an active exception
[rosout-1] killing on exit
[master] killing on exit
...

The nodelet class basically wraps another class with one publisher and one subscriber that does all the work, which is instantiated in MyNodelet::onInit(). Nothing sophisticated. ~MyNodelet() then prints the statistics using the NODELET_* / ROS_* macros after retrieving them from the worker class.

Is the nodelet destructor the proper place to be doing things like this (lacking a nodelet::onExit() or similar)? Any other ideas on how I could implement something like this?

how-to-catch-nodelet-shutdown-signal is related, but it explicitly deals with threading, which I'm not doing.

PS: Could it be that rosout doesn't get the chance to flush it buffers (or something similar)? Even a single NODELET_INFO(..) is printed only some of the time.

edit retag flag offensive close merge delete

Comments

Did adding a sleep as Jack suggested caused ROS messages to be reliably printed? I tried sleeping for 1 second and still get intermittent results. I wonder if there is a way to explicitly flush rosout...

chukcha2 gravatar image chukcha2  ( 2017-05-03 16:23:39 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-05-29 09:51:41 -0600

joq gravatar image

I have noticed similar issues even with ROS nodes: if you log a message or publish on a topic right before shutting down, it frequently gets lost.

I hate to say it, but my only suggestion is a brief sleep (maybe half a second) after the messages and before terminating the process.

edit flag offensive delete link more

Comments

I'll wait a little longer, see if anyone comes up with any other ideas. Might have to resort to the sleep-a-little work-around though.

ipso gravatar image ipso  ( 2012-05-29 11:13:23 -0600 )edit

Question Tools

Stats

Asked: 2012-05-29 05:30:51 -0600

Seen: 2,000 times

Last updated: May 29 '12