cleanup after exceptions

Peter Otten __peter__ at web.de
Fri Dec 19 09:03:01 CET 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