What happens to a thread with an unhandled exception?

Frank Millman frank at chagford.com
Fri Jun 29 10:31:18 EDT 2007


On Jun 29, 2:51 pm, Frank Millman <f... at chagford.com> wrote:
> Hi all
>
> I am doing something which works, but I have a gut feel that it cannot
> be relied upon. Can someone confirm this one way or the other.
[...]
> My worry is that the thread with the unhandled exception may
> eventually get garbage-collected, in which case the cleanup method
> will no longer be accessible. Could this happen, or does the thread
> stay in memory until termination of the main program?
>

I just noticed Diez's reply to a related question earlier today, where
he suggested wrapping the thread's run() method in a try/finally
construct. It works perfectly in my situation - if there is an
unhandled exception, my cleanup method is called before the exception
is raised. Thanks, Diez (even though you did not realise you were
helping me).

Frank




More information about the Python-list mailing list