ROS python script is not exiting after ctrl-C

asked 2018-06-18 13:00:02 -0500

vishnu gravatar image

I am trying to reset model poses in gazebo on the even "rospy.on_shutdown()". Below is the piece of code I have in my script.

def stopOnShutdown(self):
    reset_world = rospy.ServiceProxy('/gazebo/reset_world', Empty)
    print "exiting..."

But, when I press Ctrl-C, the models in the gazebo are reset but the script doesn't stop running.

edit retag flag offensive close merge delete



Not an answer, but you should really be using rospy's Time class instead of the built-in time module. rospy.Time works seamlessly with simulated Clock time.


jayess gravatar image jayess  ( 2018-06-18 13:34:54 -0500 )edit

When are you pressinc Ctrl+C and expecting it to quit but it doesn't? During the sleep() or during the reset_world()?

felix k gravatar image felix k  ( 2018-06-19 04:07:04 -0500 )edit

It is resetting the world. But it keeps on printing "exiting..." over and over even after pressing ctrl-C.

vishnu gravatar image vishnu  ( 2018-06-19 04:20:31 -0500 )edit

Have you tried removing the sys.exit() call? This might indeed create a loop

felix k gravatar image felix k  ( 2018-07-04 03:58:20 -0500 )edit