title: Stopping a Process in Python
body: <p>I am running a program that I would like to have stopped when a certain button is pushed.  </p>
  
  <p>I was thinking of running the process in the background so that the button can be pressed any time during the process and it would stop it.  </p>
  
  <p>I read stuff on subprocess from the documentation, but me being a beginner I have no idea how to use it, any help is appreciated.</p>
  
  <pre><code>def put(command):
          os.system(command)
  
          if direct == "":
              time.sleep(.5)
              arg1 = put("sudo ffmpeg -i \"" + q3 + "\" -f s16le -ar 22.05k -ac 1 - | sudo ./pifm - " + str(freq)) 
              subprocess.Popen(arg1)
              while True:
                  if RPIO.input(25) == GPIO.LOW: #if button is pushed, kill process (arg1)
                      Popen.terminate()
  </code></pre>