[PyQt] Re: Python frame never dies on application errors

Fabio Menegazzo menegazzo at esss.com.br
Wed Dec 10 16:48:40 GMT 2008


Sundance,

That's it! I didn't realized the last_traceback was keeping the reference to
the frame.

Thanks for your help!

Fabio Menegazzo

On Wed, Dec 10, 2008 at 9:26 AM, Sundance <sundance at ierne.eu.org> wrote:

> 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 at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20081210/562e5f10/attachment.html


More information about the PyQt mailing list