title: Thread While True: Loop Keeps the Code From Iterating
body: <p>I have a thread running as a daemon.</p>
  <p>In this thread I wish to continously update some variables, that are dependent on reading rows from a MySQL database.</p>
  <p>Problem is, that the program doesn't want to iterate past the While True:-loop, although it is inside of a thread. Isn't that the whole point with a thread: That I can have two loops running simultaneously?</p>
  <pre><code>import threading
  import tkinter as tk
  import pip
  import time
  import mysql.connector
  from time import sleep
  
  global score
  global countdown
  
  en = 1
  score = 0
  countdown = 1
  print(&quot;Hiya!&quot;)
  
  mydb = mysql.connector.connect(
      host=&quot;&quot;,
      user=&quot;&quot;,
      password=&quot;&quot;,
      database='',
      auth_plugin=''
  )
  
  mycursor = mydb.cursor(prepared=True)
  
  class Mysql(threading.Thread):
      def __init__(self):
          threading.Thread.__init__(self)
          self.daemon = True
          self.en = 1
          self.læsTidScoreNu = &quot;SELECT tidSCoreNu FROM bois WHERE id = 1&quot;
          self.læsTidMål = &quot;SELECT tidMål FROM bois WHERE id = 1&quot;
          self.opdaterTidMål = &quot;UPDATE bois SET tidMål = %s WHERE id = %s&quot;
          self.læsStopKnap = &quot;SELECT stopKnap FROM bois WHERE id = 1&quot;
          self.run()
  
      def run(self) -&gt; None:
          global mycursor
          global mydb
  
          while True:
              mycursor.execute(self.læsTidScoreNu)
              self.råTidScoreNu = mycursor.fetchone()
              self.tidScoreNu = float(&quot;{}&quot;.format('%.2f' % self.råTidScoreNu))
              mycursor.execute(self.læsTidMål)
              self.råTidMål = mycursor.fetchone()
              self.tidMål = float(&quot;{}&quot;.format('%.2f' % self.råTidMål))
              mycursor.execute(self.læsStopKnap)
              self.stopKnap = mycursor.fetchone()
  
  
  
              mydb.commit()
  
  
  
  data = Mysql()
  
  print(data.råTidScoreNu)
  print(data.tidMål)
  
  forevigt = 0
  
  while (forevigt != 1):
      i = 0.00
  
  
      # Servodøren skal åbnes her i denne kode
      while (data.stopKnap != 1):
          # Indtast Pinkoden
          f = int(input(
              &quot;Kodeord - bemærk her, at kodeordene er pinkoderne fra min egen database, bare indtast en værdi mellem 1-6&quot;))
          mycursor.execute(&quot;SELECT id,adresse,name,pinkode_brugt,score FROM bois WHERE id=%s&quot;, (f,))
  
          # MySQL Commands
          opdaterSlutScoren = &quot;UPDATE bois SET pinkode_brugt = pinkode_brugt +1, score = %s WHERE id = %s&quot;
          opdaterTidScoreNu = &quot;UPDATE bois SET tidScoreNu = %s WHERE id = %s&quot;
          myresult = mycursor.fetchall()
  
          row_count = mycursor.rowcount
          print(myresult)
          print(&quot;number of affected rows: {}&quot;.format(row_count))
  
          if(f == 1):
              print(&quot;ommer&quot;)
  
          else:
              if (row_count == 1):
  
                  # Servomotordøren åbner(function)
                  print(row_count)
                  print(data.tidScoreNu)
                  while (i != data.tidMål) and (i &lt;= data.tidMål) and (data.stopKnap != 1):
                      print('%.2f' % i)
                      i = i + 0.01
                      timeLeft = data.tidScoreNu - i
                      iTwo = data.tidMål
                      countdown = float('%.2f' % i)
                      score = str(&quot;{}&quot;.format('%.2f' % i))
                      mycursor.execute(opdaterTidScoreNu, (score,en))
                      print(&quot;THIS IS X&quot;, data.tidMål)
                      time.sleep(0.01)
                      mydb.commit()
  
                  # Hvis spillet stoppes, or i ikke når timerens slutværdi, vil scoren gemmes
                  if (i != data.tidScoreNu):
                      # Point bliver tilføjet
                      print(score, i, countdown, myresult)
                      print(&quot;Dette er dit resultat: {}&quot;.format(score))
                      mycursor.execute(opdaterSlutScoren, (score, f))
  
  
  
                  else:
                      # Point bliver tilføjet
                      print(&quot;Ingen point&quot;)
                      mycursor.execute(opdaterSlutScoren, (score, f))
              if row_count == 0:
                  print(&quot;fejl!&quot;)
  
              print(&quot;Færdig&quot;)
              i = 0
              mycursor.execute(opdaterTidScoreNu, (&quot;0&quot;, en))
              mydb.commit()
  
      # Mangler servo-logik, samt en timer
  </code></pre>