New to python and programming. I have a program consist of several classes, module and functions. the program runs from a main class which calls several modules and function
My question is how to implement keyboardinterrupt if the user wants to terminate a running program at any point. Do I need to implement 'try/except' method in all the functions? or this can be implementable in the main function?
To catch interrupt at any moment do I need to use try/except in all the calling functions?
def KEYBOARD_INTERRUPT():
while True:
yesnoinput=raw_input('Do you want to exit from software [Y/N]:')
if yesnoinput=='y' or yesnoinput.upper()=='Y':
sys.exit()
elif yesnoinput=='n' or yesnoinput.upper()=='N':
break
else:
continue
def A():
while True:
try:
userInput=raw_input("Please enter A")
if userInput=='A':
break
else:
continue
except KeyboardInterrupt:
KEYBOARD_INTERRUPT()
def B():
userInput=raw_input("Please enter B")
if userInput=='B':
break
else:
continue
def main():
try:
A()
B()
except:
KEYBOARD_INTERRUPT()
when main program is calling function B, at this moment if the user presses keyboardInterrupt the program will quit with error messgage, I am worried if I want to handle interrupt like KEYBOARD_INTERRUPT function I need to implement this in very function such as function A?
Did I understand wrong?