title: How to kill Subprocess run by subprocess.Popen in Python (with code)
body: <p>Firstly I would like to apologize in advance for my language skill, I am trying to bo my best to describe it clearly.</p>
  
  <p>[Python run on Raspberri Pi3 B+]</p>
  
  <p>I'm trying to kill subprocess run by subprocess.popen, I have tired searching all the web but all the solution couldn't works for me. I am beginner and not sure what i missed, I think It better to slove if someone can see my code</p>
  
  <p>Here I have my code for run subprocess</p>
  
  <pre><code>pid = subprocess.Popen([sys.executable,"01-Subprogram-serial.py"])
  </code></pre>
  
  <p>01-Subprogram-serial.py &lt;&lt; My subprogram </p>
  
  <p>This is for video playing and LED control simultaneously by raspberri pi 3 b+</p>
  
  <p>I am using Tkinter to run the button command for play video and run subprogram with serial device control, Subprogram works well only with first time running program but because of I cannot kill it, Subprogram still running even I change to another command.</p>
  
  <pre><code>from tkinter import *
  from tkinter import messagebox
  import os
  import sys
  import subprocess
  import signal
  from subprocess import Popen, PIPE
  import serial
  import time
  ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=.5)
  top = Tk()
  movie1 = ("/home/pi/Videos/VID_chap1.mp4")
  movie2 = ("/home/pi/Videos/VID_chap2.mp4")
  movie3 = ("/home/pi/Videos/VID_chap3.mp4")
  
  def vid1():
     os.system('killall omxplayer.bin')
     omxc = Popen(['omxplayer','--layer','2','--win','0,0,800,481', movie1])
     pid = subprocess.Popen([sys.executable,"01-Subprogram-serial.py"])
  #   subprocess.popen.kill(pid) &lt;This not works
  
  def vid2():
     os.system('killall omxplayer.bin')
     omxc = Popen(['omxplayer','--layer','2','--win','0,0,800,481', movie2])
     pid = subprocess.Popen([sys.executable,"02-Subprogram-serial.py"])
  #   subprocess.popen.kill(pid) &lt;This not works
  
  def vid3():
     os.system('killall omxplayer.bin')
     omxc = Popen(['omxplayer','--layer','2','--win','0,0,800,481', movie3])
     pid = subprocess.Popen([sys.executable,"03-Subprogram-serial.py"])
  #   subprocess.popen.kill(pid) &lt;This not works
  
  
  B = Button(top, text ="Asean 1", command = vid1)
  C = Button(top, text ="Asean 2", command = vid2)
  D = Button(top, text ="Asean 3", command = vid3)
  
  
  B.pack()
  C.pack()
  D.pack()
  
  top.mainloop()
  </code></pre>
  
  <p>I would like to kill the previous subprocess before it starts a new one</p>