[Python-Dev] Traceback problem

Mark Hammond mhammond@skippinet.com.au
Tue, 25 Feb 2003 11:05:51 +1100


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.

No idea if it is related or not, but this problem caused me such grief years
ago that I thought it worth mentioning.

Mark.