title: Tkinter.Tk() and threading
body: <p>There is an interesting issue with Tkinter and threading: I have a Tkinter based GUI and some code executed alongside mainloop. It works like charm if I only do it once. But if i do it twice Tkinter.Tk() blocks BOTH threads: GUI and MainThread. </p>
  
  <p>here is the code (inspired by <a href="https://stackoverflow.com/questions/459083/how-do-you-run-your-own-code-alongside-tkinters-event-loop">another Tkinter vs threading topic</a>): </p>
  
  <pre><code>import Tkinter 
  import threading
  import logging
  
  logging.basicConfig(level=logging.DEBUG, format="%(asctime)s  %(levelname)s: %(message)s")
  
  def gui():
      logging.info("Starting GUI")
      root = Tkinter.Tk() 
      logging.info("Setup GUI")
      root.after(500, root.destroy)
      root.mainloop()
      logging.info("Mainloop is over")
  
  def start_gui_thread():
      gui_thread =  threading.Thread(None, gui, None)
      gui_thread.setDaemon(True)
      gui_thread.start()    
      return gui_thread
  
  def test():
      gui_thread = start_gui_thread()    
      logging.info("Do something alongside gui")
  
      logging.info("Wait for gui to terminate")
      gui_thread.join()
      logging.info("thread terminated")
  
  logging.info("--------- 1 ---------")
  test()
  logging.info("--------- 2 ---------")
  test()
  </code></pre>
  
  <p>result: 
  winxp + python 2.7.1 (default installation)</p>
  
  <pre><code>INFO: --------- 1 ---------
  INFO: Do something alongside gui
  INFO: Starting GUI
  INFO: Wait for gui to terminate
  INFO: Setup GUI
  INFO: Mainloop is over
  INFO: thread terminated
  INFO: --------- 2 ---------
  INFO: Starting GUI
  INFO: Do something alongside gui
  </code></pre>
  
  <p>UPD 
  result with OS X 10.6.7 + python 2.7.1</p>
  
  <pre><code>MacBook-Pro:~ igann$ python test.py 
  2012-07-05 21:01:52,939  INFO: --------- 1 ---------
  2012-07-05 21:01:52,940  INFO: Starting GUI
  2012-07-05 21:01:54,835  INFO: Do something alongside gui
  2012-07-05 21:01:54,835  INFO: Wait for gui to terminate
  2012-07-05 21:01:54,835  INFO: Setup GUI
  2012-07-05 21:01:55,337  INFO: Mainloop is over
  2012-07-05 21:01:55,339  INFO: thread terminated
  2012-07-05 21:01:55,339  INFO: --------- 2 ---------
  2012-07-05 21:01:55,339  INFO: Starting GUI
  2012-07-05 21:01:55,366  INFO: Do something alongside gui
  2012-07-05 21:01:55,366  INFO: Wait for gui to terminate
  2012-07-05 21:01:55,367  INFO: Setup GUI
  Tcl_WaitForEvent: CFRunLoop finished
  Abort trap
  MacBook-Pro:~ igann$ 
  </code></pre>