cleanup after exceptions

Peter Otten __peter__ at web.de
Fri Dec 19 03:03:01 EST 2003


Tim Peters wrote:

> [Peter Otten]
>> ...
>> There seems to be some dark corner of the exception infrastructure
>> that exc_clear() doesn't touch.
> 
> It's probably just an artifact of running in interactive mode.  Then you
> also have to worry about sys.last_traceback (see the sys docs).

>>> class T:
...     def __del__(self):
...             print "i'm gone"
...
>>> def f():
...     t = T()
...     raise Exception
...
>>> import sys
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in f
Exception
>>> sys.last_traceback = None
i'm gone
>>>

You're right. No dark corners then...

Peter




More information about the Python-list mailing list