title: How to stop an audio from playing based on condition in Python?
body: <p>I am playing an audio, and simultaneously taking an input from keyboard. I have used threading to achieve this. I created a new thread to run the audio, and listening to the input from main thread. But I want to stop the audio from playing, based on a certain input from keyboard.</p>
  
  <p>Since I can't "kill" a thread from another thread, and I can't make the audio thread listen to the main thread unless it has stopped playing the audio, how do I achieve this?</p>
  
  <p>EDIT:
  I have this code written:</p>
  
  <pre><code>from multiprocessing import Process
  import os
  
  p = Process(target=os.system, args=("aplay path/to/audio/file",))
  p.start()                                                                                                                 
  print("started")                                                             
  while p.is_alive():
      print("inside loop")
      inp = input("give input")
      if inp is not None:
          p.terminate()
          print(p.is_alive())     # Returns True for the first time, False for the second time
          print("terminated")
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code>started
  inside loop
  give input2
  True
  terminated
  inside loop
  give input4
  False
  terminated
  </code></pre>
  
  <p>Why is this happening? Also, even after the second loop iteration, the process terminates (p.is_alive() returns false) but the audio keeps playing. The audio doesn't stop.</p>