I am working on ROS and I have written a code in Python 2.7
and in the menu I am asking the user to select either option 1 or 2. After the task is accomplished, when I press Ctrl+c
, instead of exiting the code, it displays the menu again, instead of exiting. Here again if I choose between 1 or 2, it keeps printing the menu again and again.
What changes in the code would be suggested in order to exit the code as soon as I press Ctrl+c
instead of displaying the menu again and again?
The code and the screen shot of the problem are below:
if __name__=='__main__':
while(True):
try:
print "***********"
print "1. Continuous"
print "2. Single Step"
print "***********"
try:
choice = int(raw_input('Choose a number between 1 & 2: '))
number = choice
move_group_python_interface()
except ValueError:
print "ERROR! Choose a number between 1 and 2"
except rospy.ROSInterruptException:
break
I found the issue. The problem was with while(True):
. Once I comment it out, it exits without any problem.