Terry J. Reedy <tjre...@udel.edu> added the comment:

For beginners, 'is this a Python bug' questions should usually be directed 
elsewhere for initial review.

https://docs.python.org/3/reference/compound_stmts.html#the-try-statement

"When an exception has been assigned using as target, it is cleared at the end 
of the except clause. This is as if

except E as N:
    foo

was translated to

except E as N:
    try:
        foo
    finally:
        del N

This means the exception must be assigned to a different name to be able to 
refer to it after the except clause. Exceptions are cleared because with the 
traceback attached to them, they form a reference cycle with the stack frame, 
keeping all locals in that frame alive until the next garbage collection 
occurs."

"l['e']" is the first new name.  "b" in each locals is the second.  Without "b 
= ..." there is no increase because l['e'] gets replaced on each call.  But 
inserting each exception into the next locals (see "keeping all locals in that 
frame alive") in effect makes a linked list of frames and locals.

If one wants to keep multiple exceptions around, best to copy just the info one 
want kept.

----------
nosy: +terry.reedy
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39782>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to