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

Stopping and re-initializing a node or stopping spin without shutting down node [closed]

asked 2017-01-20 17:36:54 -0500

lwoiceshyn gravatar image


I'm trying to write a ROS program where I initialize a server node, but once it receives one service request, it shuts down the node, and does other things, and at some later time, re-initializes the node and waits for another service request.

In my server's callback function I'm using rospy.signal_shutdown('Intentional shutdown'), but when I try and initialize the node again at some later point to wait for another service call and use rospy.spin() again, it doesn't work and seems to ignore rospy.spin(), just continuing in the program instead of waiting for another service call as I'm trying to get it to.

Anyone know why this would be happening or a different way of doing what I'm attempting here? I've tried shutting down and both the node as well as the rospy.Service object and restarting them when I'm ready to wait for the service call again from my client. I've also tried only stopping the service but then the rospy.spin() doesn't exit.

I need either a way to re-initialize the node after it's been shutdown in a single script or a way to exit the rospy.spin() loop without shutting down the node.

Any help or comments are very much appreciated.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by tfoote
close date 2017-01-22 11:53:51.015402


Why do you want to shutdown your node? This somehow looks like there is a better solution. What do you really want to achieve?

NEngelhard gravatar image NEngelhard  ( 2017-01-21 01:17:05 -0500 )edit

I agree with @NEngelhard: this might be an xy-problem. Could you perhaps give us some more context?

Also: is this (somehow) a duplicate of #q252545?

gvdhoorn gravatar image gvdhoorn  ( 2017-01-21 03:20:46 -0500 )edit
tfoote gravatar image tfoote  ( 2017-01-22 11:53:47 -0500 )edit

I'm just trying to write a service node where I go into a waiting state and wait for a client node to request that service, and once it's been requested, break out of that state and continue doing other things.

lwoiceshyn gravatar image lwoiceshyn  ( 2017-01-22 17:36:56 -0500 )edit

As @gvdhoorn mentioned this is an xy-problem. If that's all you want you don't need to shutdown or start the node. You can either manage spinning in your own main thread using spin_once, or run your main processing in a thread. Please ask a new question after trying it out.

tfoote gravatar image tfoote  ( 2017-01-22 18:20:44 -0500 )edit

Thanks for your help @tfoote. There's no spin once equivalent for rospy, right?

lwoiceshyn gravatar image lwoiceshyn  ( 2017-01-22 19:09:01 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-22 01:49:56 -0500

tfoote gravatar image

Reinitialization is not supported in the same process:

I'd recommend using a subprocess.

edit flag offensive delete link more

Question Tools



Asked: 2017-01-20 17:36:54 -0500

Seen: 2,649 times

Last updated: Jan 22 '17