Ask Your Question

Is it bad practice to create and shutdown services during runtime?

asked 2014-11-24 09:10:00 -0500

didi2002 gravatar image

Hi all!

I'm trying to connect my robot to a webserver using a node communication node.
This node creates the service "/get_webdata" when the connection is established and authenticated. When the connection is lost, the service is destroyed again. This allows me to use wait_for_service in other nodes, which is pretty useful for waiting without ugly sleep-loops.

So my question is: is this a common ros practice to use:

webdata = rospy.Service("/get/webdata", Webdata, self.web_cb)


webdata.shutdown("Connection lost")

to signal other nodes if the connection is up?
I didn't read anywhere that it's bad practice, but it feels like I'm abusing this feature. Would it be a better solution to keep the service running all the time and instead return a status variable, indicating that the connection is unavailable?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-11-24 10:03:03 -0500

Miquel Massot gravatar image

Hi didi2002!

if you are providing some sort of feedback or action after the service is called I don't see any problem. However, if the only reason why the service is online is to be able to ask if service "X" is available, then maybe a true/false parameter in the parameter server may be enough. The alternative solution that you are proposing is also valid.

edit flag offensive delete link more


The ros-service is also used by the other nodes, not only for checking if the connection is up. I like the idea of using the parameter server, but I want to avoid polling and sleeping because that introduced quite a delay.

Thanks for your reply!

didi2002 gravatar image didi2002  ( 2014-11-24 10:25:06 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-11-24 09:10:00 -0500

Seen: 243 times

Last updated: Nov 24 '14