Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

Aahz aahz at pythoncraft.com
Sat Jun 13 20:05:09 EDT 2009


In article <873aa5m6ae.fsf at vostro.rath.org>,
Nikolaus Rath  <Nikolaus at rath.org> wrote:
>
>I think I managed to narrow down the problem a bit. It seems that when
>a function returns normally, its local variables are immediately
>destroyed. However, if the function is left due to an exception, the
>local variables remain alive:

Correct.  You need to get rid of the stack trace somehow; the simplest
way is to wrap things in layers of functions (i.e. return from the
function with try/except and *don't* save the traceback).  Note that if
your goal is to ensure finalization rather than recovering memory, you
need to do that explicitly rather than relying on garbage collection.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer



More information about the Python-list mailing list