local variable not destructed if the function raised a exception

Fredrik Lundh fredrik at pythonware.com
Tue Apr 10 02:46:22 EDT 2001


"javalist" <javalist at 21cn.com> wrote:
> in f(),c1i is constructed correctly but after raise the exception(any exception),python
> didn't call c1i's destructor,in f1(),the behavior is just normal,destructor is called after
> f1() returns.anyone tell me why this happen,is this a bug or just a feature?

feature.  the traceback object (sys.exc_traceback) contains a reference to
the execution frame, which contains references to all local variables.  under
normal use, the traceback is destroyed (and all locals released) on the next
return or raise.

for more info, see sections 7.4 and 3.2 in the language reference.

Cheers /F





More information about the Python-list mailing list