title: Force a function to exit
body: <p>I've tried everything from using <code>return</code> to <code>sys.exit</code> to <code>SystemExit</code> and it doesn't work.</p>
  
  <p>I have a <code>main</code> function, that runs the 1st function; at the end of the 1st function it runs the 2nd function; at the end of the 2nd function it runs the 3rd function; and after that it asks whether I want to run the program again or exit. No matter the choice, it always returns me to <code>main</code>. </p>
  
  <p>Is there a way to force close a function inside a function inside a function inside a function?</p>
  
  <p>edit:
  example:</p>
  
  <pre><code>def main(RPNlist):
      some code here
      #this function converts a .txt file to a list, wich is a math operation
      y=list
      print(list)
      return(func2(y))
  def func2(y):
      some code here
      #this function converts the operation to reverse polish notation
      z=RPNlist
      print(RPNlist)
      return(function3(RPNlist))
  def func3(RPNlist):
      some code here
      # this solves the RPN operation
      a=answer
      print(a)
      choice=input("do you want to exit?(Input y to continue or n to exit): ")
      if choice=="y":
          return(main(x))
      elif choice=="n":
          #here's the part where I need to exit
  
  #I think this may be the issue, but is the only way I found for the whole program to run
  global RPNlist
  RPNlist=[]
  main(RPNlist)
  </code></pre>