title: Python 3 and tkinter, thread join blocks main thread forever
body: <p>So basically I have a class, let's say SerialClass, that creates a local thread to update a combobox, the constructor looks like this:</p>
  
  <pre><code>def __init__(self, master):
  
      ...
      # Local thread.
      self.__thread = threading.Thread(target=self.__thread_handler)
      self.__thread_finished = False
      self.__thread.start()
  </code></pre>
  
  <p>This is the function that the thread executes, it just updates a combobox with values.</p>
  
  <pre><code>def __thread_handler(self):
      while not self.__thread_finished:
          # Update the ports continously.
          self.update_ports()
      ...
  </code></pre>
  
  <p>This the function I use to exit the thread:</p>
  
  <pre><code>def thread_exit(self):
      self.__thread_finished = True
      self.__thread.join()
  </code></pre>
  
  <p>Another class, let's say App, instantiates the class SerialClass. App creates a Tk object and starts the main application using this method:</p>
  
  <pre><code>def run(self):
      # Handle the close window event.
      self.__root.protocol("WM_DELETE_WINDOW", self.__on_close)
      # Start the application and wait for user events.
      self.__root.mainloop()
  </code></pre>
  
  <p>This is the on_close method:</p>
  
  <pre><code>def __on_close(self):
      # When the application finishes, handle the rest of the threads.
      self.__serialui.thread_exit()
      # Destroy the root window as expected.
      self.__root.destroy()
  </code></pre>
  
  <p>The problem I have is that the program flow never reaches the root.destroy() function, for some reason the main thread is blocked forever when I call thread_exit function. If I comment the self.update_ports() in the thread_handler function, all the processes close gracefully.</p>
  
  <p>Any ideas?</p>