[Python-3000] self-contained exceptions

Jim Jewett jimjjewett at gmail.com
Tue Jan 2 21:20:39 CET 2007


On 1/1/07, Guido van Rossum <guido at python.org> wrote:

> I believe the main argument *against* having the tb included in the
> exception is that it would greatly increase the cyclic nature of
> tracebacks and stack frames, which in turn would cause lots of code to
> break due to late GC'ing of unclosed files, etc. For example, this
> code:
>
> try:
>   1/0
> except Exception, err:
>   pass
>
> will introduce a cycle from err -> traceback -> stack frame -> err,
> keeping all locals in the same scope alive until the next GC happens.

This should probably be made explicit in PEP 344.

I also keep thinking that there ought to be a solution involving weak
references, though I don't trust quite trust myself on what that
should be.  (The only obviously correct solution is to make the new
err->traceback link a weakref and not clean the sys.* interface.)

-jJ


More information about the Python-3000 mailing list