title: Terminate the Thread by using button in Tkinter
body: <p>In my GUI code, I tried to run loop1 and loop2 at the same time by clicking one button. Thus, I used <code>Thread</code> to achieve this. But I also tried to stop it by clicking another button and I failed. After searching on stackoverflow, I found out that there was no directly way to kill <code>Thread</code>. Here is the part of code:</p>
  
  <pre><code>def loop1():
      while True:
          call (["raspivid -n -op 150 -w 640 -h 480 -b 2666666.67 -t 5000 -o test.mp4"],shell=True)
          call (["raspivid -n -op 150 -w 640 -h 480 -b 2666666.67 -t 5000 -o test1.mp4"],shell=True)
  
  def loop2():
      while True:
          call (["arecord -D plughw:1 --duration=5 -f cd -vv rectest.wav"],shell=True)
          call (["arecord -D plughw:1 --duration=5 -f cd -vv rectest1.wav"],shell=True)
  
  def combine():
      Thread(target = loop1).start()
      Thread(target = loop2).start()
  
  def stop():
      Thread(target = loop1).terminate()
      Thread(target = loop2).terminate()
  </code></pre>
  
  <p>I tried to use these two buttons to control it.</p>
  
  <pre><code>btn1 = Button(tk, text="Start Recording", width=16, height=5, command=combine)
  btn1.grid(row=2,column=0)
  btn2 = Button(tk, text="Stop Recording", width=16, height=5, command=stop)
  btn2.grid(row=3,column=0)
  </code></pre>
  
  <p>I want the loop1 and loop2 can be stopped button2. Apparently there is no <code>terminate</code> in <code>Thread</code>. So I used another method <code>Process</code>. Here is the code:</p>
  
  <pre><code>from subprocess import call
  from multiprocessing import Process
  def loop1():
      while True:
          call (["raspivid -n -op 150 -w 640 -h 480 -b 2666666.67 -t 5000 -o test.mp4"],shell=True)
          call (["raspivid -n -op 150 -w 640 -h 480 -b 2666666.67 -t 5000 -o test1.mp4"],shell=True)
  def loop2():
      while True:
          call (["arecord -D plughw:1 --duration=5 -f cd -vv rectest.wav"],shell=True)
          call (["arecord -D plughw:1 --duration=5 -f cd -vv rectest1.wav"],shell=True)
  if __name__ == '__main__':
      Process(target = loop1).start()
      Process(target = loop2).start()
  </code></pre>
  
  <p>But this program finished immediately after I ran it. I know there is <code>terminate</code> function in <code>Process</code>. But I don't know how to use it.</p>