When I write a code in python which produces an infinite loop ¿How can I stopt it?
Until now I save the program and close the constructor…
you can exit a loop if a condition is met like this:
while True: if condition == True: break
chk = True 1. while chk == True: ... if condition == True: chk = False
while True: try: ... except: break
otherwise you can always press ctrl+c in the terminal, sometimes ctrl+d or ctrl+z also work
for ROS, this is a very solid solution:
ctrl_c = False
def shutdownhook():
# works better than the rospy.is_shut_down()
global ctrl_c
print "shutdown time!"
ctrl_c = True
rospy.on_shutdown(shutdownhook)
while not ctrl_c:
"do stuff"
1 Like
Hello Simon.
Thanks for your answer but there is a missunderstood.
What I mean is how to stop the program once it is running and I forgot to add the “break” in the “while”
sometimes you have to spam it (holding down ctrl and then c)
1 Like
Thanks Simon for your time
1 Like