title: Python: stop one incidence of recursive function and run another without resuming the first
body: <p>I am trying to make a game using a countdown timer for 60s.</p>
  <p>My issue is that as the countdown timer is recursive, it keeps running until t == 0 when it runs the endgame() function.</p>
  <p>if you pass the level, the initial countdown timer will still end after 60s which in turn will end the game. I need a way to run the next level without the initial countdown ending and ending the game.</p>
  <p>I have tried using if True statements at the start of the function which only paused the loop until the next instance of the function started.</p>
  <p>code:</p>
  <pre><code>from tkinter import *
  import ctypes
  from scrambld_back import *
  from tkinter import font
  import time
  from nltk.corpus import words
  
  user32 = ctypes.windll.user32
  screensize = [user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)]
  
  root = Tk()
  root.geometry(f'500x500+{screensize[1]-250}+100')
  root.title('Scrambld')
  root.configure(bg='white')
  
  over = Tk()
  over.geometry(f'500x500+{screensize[1]-250}+100')
  root.title('Scrambld')
  root.configure(bg='white')
  over.iconify()
  
  gamefont = font.Font(family='impact', size=30)
  levelfont = font.Font(family='impact', size=20)
  
  level = 0
  Label(over, text='GAME OVER', font=gamefont)
  Label(over, text=f'Level {level}', font=levelfont)
  
  def endgame():
      over = Toplevel(root)
      over.geometry(f'500x500+{screensize[1]-250}+100')
      Label(over, text='GAME OVER', font=gamefont).place(x=250, y=215, anchor='center')
      Label(over, text=f'Level {level}', font=levelfont).place(x=250, y=285, anchor='center')
  
  def play(level):
      t = 15
      gamewords = []
      for x in words.words():
          if len(x) == level+3:
              gamewords.append(x)
      word = gamewords[random.randint(0, len(gamewords))]
      gameplay = generate(list(word))
      Label(root, text=f'Level {level}', font=levelfont, bg='white').place(x=250, y=70, anchor='center')
      Label(root, text=gameplay, font=gamefont, bg='white', width=100).place(x=250, y=140, anchor='center')
  
      guess = Entry(root, font=levelfont, bg='white')
      guess.place(x=250, y=360, anchor='center')
      guess.bind('&lt;Return&gt;', lambda event, word=word: compare(event, word))
  
      def compare(event, word):
          if word.upper() == guess.get().upper():
              play(level+1)
          else:
              pass
  
      submit = Button(root, text='SUBMIT', font=levelfont, bg='white', width=21, command=lambda: compare(None, word))
      submit.place(x=250, y=420, anchor='center')
  
      timer = StringVar()
      Label(root, textvariable=timer, font=levelfont, bg='white', width=8).place(x=250, y=250, anchor='center')
      def countdown(t, lev):
          print(lev, level)
          print(t)
          t=int(t)-1
          if t &lt; 10:
              t=f'0{t}'
          timer.set(f'00:{t}')
          root.update()
          if int(t) &lt; 1 and lev == level:
              endgame()
          else:
              root.after(1000, lambda: countdown(t, lev))
          
      countdown(t, 1)
  
  play(1)
  </code></pre>