Sundance,<br><br>That&#39;s it! I didn&#39;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">&lt;<a href="mailto:sundance@ierne.eu.org">sundance@ierne.eu.org</a>&gt;</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>
&gt; Consider a widget in the display. When an exception happens the Python<br>
&gt; 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&#39;s refcount doesn&#39;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&#39;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>
 &nbsp;def __init__( s ):<br>
 &nbsp; &nbsp;print &quot;I&#39;m a stub instance and I was just created!&quot;<br>
<br>
 &nbsp;def __del__( s ):<br>
 &nbsp; &nbsp;print &quot;Whoops, my refcount is zero and now I die!&quot;<br>
<br>
<br>
class TestClass:<br>
<br>
 &nbsp;def causeHavoc( s ):<br>
<br>
 &nbsp; &nbsp;stub = Stub()<br>
 &nbsp; &nbsp;raise Exception( &quot;Whoops, an error occurred!&quot; )<br>
<br>
 &nbsp;def clearTraceback( s ):<br>
<br>
 &nbsp; &nbsp;print &quot;Deleting last traceback...&quot;<br>
 &nbsp; &nbsp;sys.last_traceback = None &nbsp;## HERE!<br>
<br>
 &nbsp;def start( s ):<br>
<br>
 &nbsp; &nbsp;app = Qt.QApplication( sys.argv )<br>
 &nbsp; &nbsp;Qt.QTimer.singleShot( 1000, s.causeHavoc )<br>
 &nbsp; &nbsp;Qt.QTimer.singleShot( 2000, s.clearTraceback )<br>
 &nbsp; &nbsp;Qt.QTimer.singleShot( 3000, app.quit )<br>
 &nbsp; &nbsp;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&#39;t know about. :)<br>
<br>
Hope this helps,<br>
<br>
-- S.<br>
_______________________________________________<br>
PyQt mailing list &nbsp; &nbsp;<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>