title: Stuck in a loop - Threaded continues while loop prevents code from moving forward (Python)
body: <hr>
  
  <p><strong>EDIT:
  I apparantly wasn't aware of daemon threads.. This solved the main issue..
  Now just puzzling to keep the loop checking for button press, whether it has been pressed or not =)</strong></p>
  
  <hr>
  
  <p>I'm trying to stop a raspberry pi running code when I press a button (emergency stop button connected to the pins).</p>
  
  <p>So far it's not working out. (In my example code I use code to switch the light of the button to make testing easier).</p>
  
  <p>The threading seems to be working well, however the shell program installed in the pi running the code, first 'test runs' the code to check for errors before actually executing. In my while not <code>read_button()</code> code, the 'checking' of the code gets stuck on the 'while not' until I press the button; not ideal..</p>
  
  <p>Reversing the code and having <code>while read_button()</code> or only <code>if read_button()</code> doesn't actually respond to my button press, since likely the code finishes after checking instead of continuously check.</p>
  
  <p>So.. How to solve this? A continues loop stops my code from proceeding until the while loop is broken (I did join the thread in the end..). A non-continues loop doesn't function, since it won't continuously check for the button press..</p>
  
  <p>To make things worse; after the emergency stop was performed I want the thread to still continue checking for button press after (the user might decide to resume the program and have to hit emergency stop again later on the way within the same code).</p>
  
  <p>I feel like I'm in an endless loop myself trying to fix this =P</p>
  
  <p>(Sorry for the lengthy post and sorry for any noob-terms used, I'm very new to this; only picked programming up 3 weeks ago)</p>
  
  <p>Thank you very much in advance!!</p>
  
  <pre><code>def button_check():
      while not read_button():        #developer API
          if read_button():
              set_button_light(blue=True)   #developer API
  
  
  
  t = Thread(target=button_check)
  t.start()
  
  time.sleep(20)      #just to give me time to test
  
  t.join()
  </code></pre>