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 simple queue running on the main thread so that I can ensure that UI updates happen one at a time.
I’m having trouble getting my head around how I’d set up my event loop, though. In general you’d do something like
while True:
try:
callback = queue.get(False)
except Queue.Empty:
break
callback()
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?