[Python-Dev] Traceback problem
Christian Tismer
tismer@tismer.com
Tue, 25 Feb 2003 02:00:00 +0100
Mark Hammond wrote:
> I'm not completely clear on the problem being described here, but:
>
>
>>Sure, it is possible for long-running functions to wrap
>>any exception-raising stuff into an extra wrapping function
>>that always returns after the exception has happened,
>>and to let the main worker function run without try..except.
>>But is this very cool?
>
>
> I point out that the following code:
>
> import sys
> def a():
> try:
> 1/0
> except:
> t, v, tb = sys.exc_info()
>
> if __name__=='__main__':
> while 1:
> a()
>
> When garbage collection is not enabled will cause huge memory leaks. The
> problem is the "tb" variable - the traceback holds a reference to the stack
> frame, which holds references to the locals, which holds a reference back to
> "tb".
>
> gc clears these cycles, so later Python versions work fine - does stackless
> enable gc? Explicitly setting "tb" to None in the exception handler also
> fixes it.
Thanks a lot. Yes, I know about this and advised them
to clear t, v, tb after usage, which breaks the cycle.
The problem is just that they don't like to use an extra
wrapper function around the exception, but want to handle
it in their top-level worker loop.
When an exception happens there, it isn't cleared until
another one happens, or the function leaves.
But the latter never happens...
ciao - chris
--
Christian Tismer :^) <mailto:tismer@tismer.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/