title: How to wait until my pynput listener finishes? Python
body: <p>I've ran into this problem where I want to delete a file once my pynput listener has finished (by finished I mean that the program has closed) since the listener only stops if the program has been closed, how can I make a statement afterward the listener has stopped?</p>
  <pre><code>def on_press(key):
     print(&quot; pressed : {0}&quot;.format(key))
  
  with Listener(on_press=on_press) as listener:
      listener.join()
  
  os.remove(file_path)
  </code></pre>
  <p>so basically, i want to remove the file_path afterwards the Listener has finished, but by the time the listener has finished, the whole program itself has stopped.</p>
  <p>but i dont want to stop the listener until the app closes, so basically im asking how can i delete a file when I stop the program.</p>