Starting a thread before wxPython bootup ... interesting.
Chris Mellon
arkanes at gmail.com
Thu Oct 4 14:35:09 EDT 2007
On 10/4/07, Shafik <shafik23 at gmail.com> wrote:
> Hello folks,
>
> I'm having an issue with mixing wxPython and threading ... I realize
> multi-threading always introduces subtle bugs, but the following
> scenario is just odd:
>
> I start a dummy thread, that does nothing but increment a counter and
> print its value to the screen, then afterwards, I start the wxPython
> application. I get nothing but weird behavior: sometimes the gui just
> crashes, sometimes I get an exception, sometimes it runs for a little
> but very slowly ...
>
> Anyone know whats going on? I have a dual-core T5500, so multi
> threading is piece of cake for it hardware -wise.
>
That's quite a broad and poorly specified problem to ask people to
solve with no code. You get double minus points for mentioning an
exception without saying what it was.
Below is a script that has no demonstrable problems on my machine:
import wx
import threading
if __name__ == '__main__':
run = True
def count():
counter = 0
while run:
print counter
counter += 1
thread = threading.Thread(target=count)
thread.start()
app = wx.App(False)
f = wx.Frame(None)
f.Show()
app.MainLoop()
run = False
Since the counter loop spins tightly, this causes some CPU contention
and could quite possibly cause a non-trivial GUI to respond poorly,
but that's to be expected.
More information about the Python-list
mailing list