wxPython: non-GUI thread launching new frame? Delegates?

Diez B. Roggisch deets at nospam.web.de
Tue Feb 20 06:48:07 EST 2007


cyberco wrote:

> In my wxPython app a non-GUI thread (that reads info from the network)
> tries to open a frame to show the new info. This results in my app
> hanging (which is not too surprising). Coming from a C# environment I
> wonder if there is some sort of delegate mechanism in wxPython to do
> this sort of thing.

Not sure how wx deals with this, but one thing you might explore is the
possibility to add a timer in the GUI-thread, that polls a thread-filled
queue.

Other toolkits as Qt have means to insert an extra event in the event queue
of the gui-thread in a thread-agnostic way, maybe wx has that too.

Googling...
...
...
...

... finished

http://mail.python.org/pipermail/python-list/2005-August/335467.html

"""
You need another way to pass completion information between the downloader
thread and the main thread; the simplest way is to define a custom wx
Event, and wxPostEvent from the downloader thread when it completes (
and when the gauge should be updated).  wxPostEvent is safe to call from
non-eventloop threads.
The main thread's wx event loop just spins, properly updating all other
parts of the GUI, and receiving events from the downloader thread.

ANother approach is to have a thread-safe Queue and have the main
thread/event loop
poll the queue with queue.get_nowait() periodically (typically 0.1-1 sec).
The downloader thread shares the queue object and puts data structures
(typically
class instances, strings, or ints) that indicate status updates.
"""

So - both options a viable. And read to the end, the twisted-approach
certainly is the most clean one.

Diez



More information about the Python-list mailing list