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.

rospy.on_shutdown(self.stopOnShutdown)
def stopOnShutdown(self):
    time.sleep(1)
    reset_world = rospy.ServiceProxy('/gazebo/reset_world', Empty)
    reset_world()
    print "exiting..."
    sys.exit(0)

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

Comments

1

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.

See http://wiki.ros.org/rospy/Overview/Ti...

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