title: Implementing my own event loop in a wxPython application
body: <p>I’m writing a wxPython application that will be doing quite a bit of data analysis and display. The way I’ve written it so far has led to problems when two threads try to change something in the GUI at the same time. What I want to do is to set up my own <a href="https://stackoverflow.com/a/18990710/371228">simple queue running on the main thread</a> so that I can ensure that UI updates happen one at a time.</p>
  
  <p>I’m having trouble getting my head around how I’d set up my event loop, though. In general you’d do something like</p>
  
  <pre><code>while True:
      try:
          callback = queue.get(False)
      except Queue.Empty:
          break
      callback()
  </code></pre>
  
  <p>I assume that if I run that code as-is then WX will not be able to do its thing because it will never receive any events or anything because control never leaves my infinite loop. How can I make this kind of structure coexist with the WX event loop? Or more generally, in a WX application how can I ensure that a certain task is only ever run on the main thread?</p>