I am looking for a way to break out of a function and the loop that it is called in with some sort of interrupt. Ideally if the user presses a particular key the loop ends and the code goes back to asking the user for an input.
Pseudo code below...
def main():
#main loop
while True:
#user asked to select an option
inp = input()
if inp == "option_1":
#option 1 loop
while True:
perform_option1()
elif inp == "option_2":
#option 2 loop
while True:
perform_option2()
elif inp == "quit":
#exit the program
exit()
Just to be clear the program asks the user for an input. Based on that input we move into one of two infinite loops. I am looking for a way to break these loops when the user presses a particular key and go back to the initial loop where the program will ask the user for an input again. I do not want to use input() or any other method where the code needs to stop and wait for input. I feel like this can be solved by threading or maybe a custom exception (no idea how to do that currently) and have read several other similar questions but can't for the life of me wrap my head around a way to make this work.
If possible I would love to use a standard library to accomplish this. Thanks very much for your help.