wxpython thread exception crash

Stephen Hansen apt.shansen at gmail.com
Tue Aug 21 06:31:07 CEST 2007

On 8/20/07, [david] <david at nospam.spam> wrote:
> What am I doing wrong?
> I'm trying to capture stdErr in a multi-threaded program.

You can't reliably access the GUI anywhere except in the main thread; you're
printing to stderr from the worker thread, and thus its writing to the GUI
control, and that action is occuring within the worker thread. Sometimes
it'll work. Eventually it'll always fail.

Try adjusting the write method of RedirectText to:

    def write(self,string):
        wx.CallAfter(self.out.WriteText, string)

"wx.CallAfter" is a convienence function to call from a worker thread "into"
the GUI thread and execute the specified method with the given options. It
makes modifying the GUI very easy.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070820/25a99a5e/attachment.html>

More information about the Python-list mailing list