
noreply at sourceforge
Dec 27, 2000, 3:21 PM
Post #6 of 6
(230 views)
Permalink
|
|
[Bug #126254] Traceback objects not properly garbage-collected
[In reply to]
|
|
Bug #126254, was updated on 2000-Dec-18 17:50 Here is a current snapshot of the bug. Project: Python Category: Python Interpreter Core Status: Closed Resolution: Invalid Bug Group: Not a Bug Priority: 5 Submitted by: nobody Assigned to : gvanrossum Summary: Traceback objects not properly garbage-collected Details: 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 [at] commerceflow Follow-Ups: Date: 2000-Dec-27 14:21 By: gvanrossum Comment: Note that the bug report was about 1.5.2 and 1.6. This should be fixed by the cycle collection in 2.0, shouldn't it? ------------------------------------------------------- Date: 2000-Dec-20 18:59 By: tim_one Comment: "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 <wink>: you may not like the answer, but Guido is saying it's functioning as designed and he has no plans to change that. ------------------------------------------------------- Date: 2000-Dec-20 18:50 By: nobody Comment: oops, didn't see you comment. Forget about my question... Phil - phil [at] commerceflow ------------------------------------------------------- Date: 2000-Dec-20 18:49 By: nobody Comment: Could I know why this was deemed to be `Invalid' ? Phil - phil [at] commerceflow ------------------------------------------------------- Date: 2000-Dec-18 20:21 By: gvanrossum Comment: 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 [at] python ------------------------------------------------------- For detailed info, follow this link: http://sourceforge.net/bugs/?func=detailbug&bug_id=126254&group_id=5470
|