Multiple threads in a GUI app (wxPython), communication between worker thread and app?
Paul Rubin
http
Sun May 1 13:09:56 EDT 2005
"fooooo" <phark52 at yahoo.com> writes:
> How would I get the worker thread to open a GUI window in the main GUI
> thread? After that GUI window is open, how can I send and recv messages
> from/to the GUI window?
First of all the favorite Pythonic way to communicate between threads
is with synchronized queues--see the Queue module. Have the worker
thread put stuff on a queue and have the main GUI thread read from it.
Secondly, I don't know about wxPython, but in tkinter you have to
resort to a kludge in order for the gui thread to handle gui events
and also notice stuff on a queue. There's a tkinter command to run
some function after a specified time (say 50 msec). So you'd set that
timeout to check the queue and restart the timer, which means the gui
would check 20x a second for updates from the worker threads. When it
got such an update, it would create a new window or whatever.
It could be that wxPython has a cleaner way of doing this, or you
might have to do something similar. Python thread support seems to
have been something of an afterthought and there's a lot of weirdness
like this to deal with.
More information about the Python-list
mailing list