worker thread catching exceptions and putting them in queue

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Mar 8 15:36:28 EST 2007


En Thu, 08 Mar 2007 13:31:14 -0300, Aahz <aahz at pythoncraft.com> escribió:

> In article <45ec4936$0$323$e4fe514c at news.xs4all.nl>,
> Paul Sijben  <paul.sijben at xs4all.nl> wrote:
>>
>> in a worker thread setup that communicates via queues is it possible to
>> catch exceptions raised by the worker executed, put them in an object
>> and send them over the queue to another thread where the exception is
>> raised in that scope?
>
> One caution: because exceptions keep stack frames alive, you can have
> garbage collection problems.  Make sure to del the exception when you're
> done with it.

Note that it's the traceback who keeps stack frames alive, not the  
exception itself (at least on the current Python versions, might change in  
the future). If no fancy processing of the traceback is needed, maybe  
converting it to string (using the traceback module) before posting it to  
the queue is enough.

-- 
Gabriel Genellina




More information about the Python-list mailing list