System info: ============ Python 2.0 (#1, Dec 18 2000, 16:47:02) [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2 Linux phil 2.2.18 #1 Mon Dec 18 14:49:56 PST 2000 i686 unknown Sample code: ============ import sys class fooclass: def __init__(self): print 'CONSTRUCTED' def withtb(self, doit=0): try: raise "foo" except: if doit: tb = sys.exc_info()[2] def __del__(self): print 'DESTROYED' if __name__ == '__main__': foo = fooclass() if len(sys.argv) > 1: foo.withtb(1) else: foo.withtb(0) del foo How to reproduce: ================= Run the above python script: 1. Without any argument: the withtb() method exception handler does not retrieve any traceback object. The program prints `CONSTRUCTED' and `DESTROYED'. 2. With some arguments: the withtb() method exception handler retrieves a traceback object and stores it in the `tb' local variable. However `DESTROYED' never gets printed out. I think that the `foo' object will never be garbage collected anymore. Workaround: =========== Deleting the `tb' object seems to restore things: if doit: tb = sys.exc_info()[2] del tb Other: ====== I've found this problem also in python 1.5.2 and python 1.6. Possible cause: =============== I would tend to think that we're creating a circular loop which cannot be garbage collected: - `tb' holds a reference to the traceback object - the traceback object holds a reference to the local scope - the local scope holds a reference to the `tb' variable The only way out is to break the circular reference by hand, although it's annoying. Phil - phil@commerceflow.com.
This is not a bug. Saving the traceback as a local variable creates a circular reference that prevents garbage collection. If you don't understand this answer, please write help@python.org.
"Invalid" is a just a word -- it comes with SF bug system and isn't defined anywhere. By convention, we pair Not-A-Bug with Invalid, for lack of something better to do. Not-A-Bug means it's not a bug : you may not like the answer, but Guido is saying it's functioning as designed and he has no plans to change that.