threads and exception in wxPython

Josiah Carlson jcarlson at uci.edu
Wed Nov 3 17:30:29 EST 2004


Zunbeltz Izaola <zunbeltz at wm.lc.ehu.es.XXX> wrote:
> 
> Josiah Carlson <jcarlson at uci.edu> writes:
> 
> > from StringIO import StringIO
> > import traceback
> > import Queue
> > 
> > traceback_queue = Queue.Queue()
> > 
> > ...
> >     def run(self):
> >         try:
> >             ...
> >         except:
> >             tb = StringIO()
> >             traceback.print_exc(tb)
> >             traceback_queue.put(tb.getvalue())
> > ...
> > 
> > 
> >  - Josiah
> > 
> 
> Ok, thanks for the help. But  I still have a problem. When the lines
> in the try block raise an exception it is saved in the traceback_quee
> and the thread is finished. Is that correct?. The problem is how do I
> inspect the queue? The function that creates the thread is something
> like that
> 
>     def OnMeasurement(self):
>         self.CurrentMeasurement.start()
> 
> If I put some code after the .start() method the queue will be
> empty. Do I need to insert a infinite loop to see when the exception
> is raised?

In your main thread (the one handling the GUI), you can set up a
wx.Timer() whose bound event checks the queue every second or so.

As another poster mentioned, you can also post events to the GUI, which
can either say "there is an exception traceback in the queue" or "here
is the exception traceback".

It is really all a matter of taste.


 - Josiah




More information about the Python-list mailing list