title: Tkinter: Wait for item in queue
body: <p>I’m using a queue to exchange messages between a background thread and a Tk GUI application. Currently, this is done by calling a query method every now and then.</p>
  
  <pre><code>def read_queue(self):
      try:
          self.process(self.queue.get(False)) # non-blocking
      except Queue.Empty:
          pass
      finally:
          self.after(UPDATE_TIME, self.read_queue)
  </code></pre>
  
  <p>The problem with this approach is that if <code>UPDATE_TIME</code> is too large, the application will process new items slower than possible. If it is too small, Tk spends most of the time checking the queue although it could do other stuff in the meantime.</p>
  
  <p>Is there a way to automatically trigger the <code>read_queue</code> method whenever a new item arrives in the queue? (I could certainly call a method on Tk when the background thread fills the queue but I fear that this gives me some concurrency issues – that’s why I’m using queues after all.)</p>