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

exit from rospy.is_shutdown(): without shutdown node

asked 2018-12-20 04:55:03 -0500

leogeo gravatar image

updated 2019-01-08 14:18:03 -0500

jayess gravatar image

i am using while not rospy.is_shutdown(): loop in a function but i can't exit from the function

how i can exit from while not rospy.is_shutdown() loop without shutting down the node i have issue to exit from function()

def function():
   while not rospy.is_shutdown():

def clbk_laser(msg):

def main():
    rate = rospy.Rate(20)
    while not rospy.is_shutdown():
if __name__ == '__main__':


i tried many ways like exit break return .. without result get out from while not rospy.is_shutdown() loop i think is different because using sys.exit(0) i shutdown the node and return or break do nothing i keep inside the loop

edit retag flag offensive close merge delete


Can you provide your code and more details about what you want to achieve please ? This loop can only be exited with CTRL-C.

Delb gravatar image Delb  ( 2018-12-20 05:02:48 -0500 )edit

Thank you for the edit. Why are you using a while not rospy.is_shutdown() loop if you want to exit it without shutting down the node ? You should use something like :

condition = 0
while (condition == 0)
    #do what you want
    if another_condition
        condition = 1
Delb gravatar image Delb  ( 2018-12-21 01:56:54 -0500 )edit

Update : Can you also update the code when using break ? That should exit the loop if correctly used. Also if you could detail why you are using a while not rospy.is_shutdown inside a function called in a callback could be helpful because that's not a common thing to do.

Delb gravatar image Delb  ( 2019-01-09 02:21:55 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2021-01-15 01:33:08 -0500

KonohaHokage gravatar image

You can always use the python "break" keyword to break out of any loop even if the loop condition is still true.

See more about it in python tutorial.

Ping me if it solved your problem.

edit flag offensive delete link more

answered 2018-12-20 10:09:51 -0500

You can use the python break command to break out of any while or for loop even if the loop condition is still true.

See the description in the documentation here.

Is this what you're trying to achieve?

edit flag offensive delete link more

Question Tools



Asked: 2018-12-20 04:55:03 -0500

Seen: 4,648 times

Last updated: Jan 08 '19