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

rospy rqt - shutdown?

asked 2014-05-08 22:50:08 -0500

Hendrik Wiese gravatar image

Hi folks,

this tutorial asks to shutdown publishers and subscribers in the overloaded shutdown_plugin method but doesn't explain how this is done. I couldn't find any advice on how to shutdown a publisher and unsubscribe a subscriber. Could anyone guide me? Thanks

Cheers, Hendrik

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-05-08 23:42:11 -0500

130s gravatar image

updated 2014-05-09 00:47:10 -0500

Example of stopping Subscriber in rqt plugin in rospy

In shutdown_plugin you can do basically whichever way you usually do to finish your ROS process.

I'll take rqt_plot as an example. In a class derived from rqt_gui_py.plugin (which I'm sure you've already made in your case), there's shutdown_plugin defined as:

def shutdown_plugin(self):

Then the method called above is defined here in a widget class

def clean_up_subscribers(self):
    for topic_name, rosdata in self._rosdata.items():

rosdata.close() is defined here that internally calls rospy.Subscriber.unregister.

This isn't the simplest example but you should get the idea.

(Update) Example of stopping Publisher in rqt plugin in rospy

There aren't many rqt plugins out there that explicitly stop publishing topics, but looks like rqt_bag does in the following sequence (indices at the beginning of each line are linking to the actual code):


def shutdown_plugin(self):


def shutdown_all(self):


def handle_close(self):
    for topic in self._get_topics():


def stop_publishing(self, topic):
    if not self._player:
        return False


And 5

    if topic in self._publishers:
        del self._publishers[topic]
edit flag offensive delete link more


My question more relates to the actual shutdown of publishers and subscribers than the plugin. I should have made that clearer. You answered on how to shutdown a subscriber. Is it the same for publishers?

Hendrik Wiese gravatar image Hendrik Wiese  ( 2014-05-08 23:48:26 -0500 )edit

I added my finding about publisher to my answer.

130s gravatar image 130s  ( 2014-05-09 00:47:44 -0500 )edit

Thanks a lot. Looks like it's a bit more complex to shutdown a publisher... is it actually really necessary?

Hendrik Wiese gravatar image Hendrik Wiese  ( 2014-05-09 01:05:39 -0500 )edit

Answer should be "no"; I just referred to the entire steps only because I have no experience in stopping publisher with rqt python plugin. In essence you should just be able to stop by calling `unregister`.

130s gravatar image 130s  ( 2014-05-09 01:43:41 -0500 )edit

Alright, I'll do it by just calling unregister. It basically shouldn't be that much of an issue in my config anyway. So... thanks a lot!

Hendrik Wiese gravatar image Hendrik Wiese  ( 2014-05-09 02:26:54 -0500 )edit

Question Tools

1 follower


Asked: 2014-05-08 22:50:08 -0500

Seen: 760 times

Last updated: May 09 '14