Sundance,<br><br>That's it! I didn't realized the last_traceback was keeping the reference to the frame.<br><br>Thanks for your help!<br><br>Fabio Menegazzo<br><br><div class="gmail_quote">On Wed, Dec 10, 2008 at 9:26 AM, Sundance <span dir="ltr"><<a href="mailto:sundance@ierne.eu.org">sundance@ierne.eu.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Fabio Menegazzo wrote:<br>
<br>
> Consider a widget in the display. When an exception happens the Python<br>
> frame never dies. Am I doing something wrong?<br>
<br>
Hi Fabio,<br>
<br>
In your example, your exception occurs while the frame for<br>
SlotRaiseError() is still on the stack. The traceback thus keeps a<br>
pointer to that frame, which is why the stub variable's refcount doesn't<br>
reach 0. You are trying to use sys.exc_clear(), but that function makes<br>
strictly no promise as to what variables are going to get cleared, or<br>
when (see <a href="http://effbot.org/pyref/sys.exc_clear.htm" target="_blank">http://effbot.org/pyref/sys.exc_clear.htm</a>). In particular, it<br>
doesn't clear the reference to the last traceback that is available in<br>
the sys module.<br>
<br>
Contrast the example:<br>
<br>
---[ Example ]---------------------------------------------------------<br>
import sys<br>
from PyQt4 import Qt<br>
<br>
class Stub:<br>
<br>
def __init__( s ):<br>
print "I'm a stub instance and I was just created!"<br>
<br>
def __del__( s ):<br>
print "Whoops, my refcount is zero and now I die!"<br>
<br>
<br>
class TestClass:<br>
<br>
def causeHavoc( s ):<br>
<br>
stub = Stub()<br>
raise Exception( "Whoops, an error occurred!" )<br>
<br>
def clearTraceback( s ):<br>
<br>
print "Deleting last traceback..."<br>
sys.last_traceback = None ## HERE!<br>
<br>
def start( s ):<br>
<br>
app = Qt.QApplication( sys.argv )<br>
Qt.QTimer.singleShot( 1000, s.causeHavoc )<br>
Qt.QTimer.singleShot( 2000, s.clearTraceback )<br>
Qt.QTimer.singleShot( 3000, app.quit )<br>
app.exec_()<br>
<br>
t = TestClass()<br>
t.start()<br>
-----------------------------------------------------------------------<br>
<br>
In this example, the stub variable is correctly collected when the<br>
reference to the traceback is deleted.<br>
<br>
In short: business as usual. Python works fine, it just keeps a<br>
reference to the last traceback that you didn't know about. :)<br>
<br>
Hope this helps,<br>
<br>
-- S.<br>
_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
</blockquote></div><br>