wxPython blocks in thread?

Jeff Shannon jeff at ccvcorp.com
Thu Feb 28 15:40:20 EST 2002


Arnaud de La Fortelle wrote:

> I am a beginner with wxPython and tried to embed a GUI within a
> thread.  So I came with a simple implementation, but it does not work.
> I do not understand why the following application blocks. What the
> matter?

I seem to remember some discussion on the wxPython-users mailing list,
recently, that indicated that wxPython considers the "main thread" to be
the one that first imports wxPython.wx.  You're running your app in a
thread that has never imported wxPython -- the Python interpreter will
accept it, but the underlying wxWindows framework may be having problems.
(I may be misremembering the details on this, though -- you can check the
recent archives of the mailing list from www.wxpython.org.)

Can you invert your thread usage?  Instead of having some other program
fire off a thread that does the GUI, have the GUI part be the main thread
and then *it* fires off various worker threads.

If not, then you might be able to simply wait until you're *in* your
thread, to import wxPython and declare your wxApp, like so:

class GUIThread(threading.Thread):
    def Run(self):
        from wxPython.wx import *
        class MyApp(wxApp):
            def OnInit(self):
                ....
        self.app = MyApp(0)
        self.app.MainLoop()

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list