title: How to stop a Thread - Python 3
body: <blockquote>
    <p>Hi guys, I am struggling trying to stop a thread, I don't get any error but my thread don't stop. I would appreciate some help. I have a button who call my function lev which should stop the thread when I turned my button off. Follow the part of the code below:</p>
  </blockquote>
  
  <pre><code>exitFlag = 0
  
  def levt():
  
      print("Executando")
      while ((app.frames[Acionamento].var.get()==2) and exitFlag==0):
          print("o thread")
          t1fvm = time.time()  #Tempo final luminária esquerda
          n1mv = (t1fvm-t1ivm)*0.6
          global levm
          levm = levm+n1mv
          print(levm)
  
  
  
  
  def lev():
  
      app.frames[Acionamento].esquerdaFrame.vendasFrame.luminaria_esquerdaFramev.label6["text"] = "Luminária A"
      global exitFlag
      global thread2
      thread2 = Thread(target=levt)    
      if GPIO.input(17):
          GPIO.output(17, GPIO.LOW)
          app.frames[Acionamento].esquerdaFrame.vendasFrame.luminaria_esquerdaFramev.lev_button["text"]="Desligado"
          if thread2.isAlive():
              exitFlag = 1
  
      else:
          global t1ivm
          t1ivm = time.time()   
          GPIO.output(17, GPIO.HIGH)
          app.frames[Acionamento].esquerdaFrame.vendasFrame.luminaria_esquerdaFramev.lev_button["text"]="Ligado"
          thread2.start()
  </code></pre>