Fabio Menegazzo wrote: > Consider a widget in the display. When an exception happens the Python > frame never dies. Am I doing something wrong?
Hi Fabio, In your example, your exception occurs while the frame for SlotRaiseError() is still on the stack. The traceback thus keeps a pointer to that frame, which is why the stub variable's refcount doesn't reach 0. You are trying to use sys.exc_clear(), but that function makes strictly no promise as to what variables are going to get cleared, or when (see http://effbot.org/pyref/sys.exc_clear.htm). In particular, it doesn't clear the reference to the last traceback that is available in the sys module. Contrast the example: ---[ Example ]--------------------------------------------------------- import sys from PyQt4 import Qt class Stub: def __init__( s ): print "I'm a stub instance and I was just created!" def __del__( s ): print "Whoops, my refcount is zero and now I die!" class TestClass: def causeHavoc( s ): stub = Stub() raise Exception( "Whoops, an error occurred!" ) def clearTraceback( s ): print "Deleting last traceback..." sys.last_traceback = None ## HERE! def start( s ): app = Qt.QApplication( sys.argv ) Qt.QTimer.singleShot( 1000, s.causeHavoc ) Qt.QTimer.singleShot( 2000, s.clearTraceback ) Qt.QTimer.singleShot( 3000, app.quit ) app.exec_() t = TestClass() t.start() ----------------------------------------------------------------------- In this example, the stub variable is correctly collected when the reference to the traceback is deleted. In short: business as usual. Python works fine, it just keeps a reference to the last traceback that you didn't know about. :) Hope this helps, -- S. _______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt