[PyQt] Exceptions and stack frames

Phil Thompson phil at riverbankcomputing.com
Fri Aug 20 09:52:35 BST 2010

On Thu, 19 Aug 2010 20:48:46 +0100, Jeremy Sanders
<jeremy at jeremysanders.net> wrote:
> I have a problem with stack frames hanging around after exceptions in
> objects.
> A particular method on a PyQt object is connected to a signal. This
> is called because of the signal is raised.
> If I get an uncaught exception in that method, then there appears to be
> stack frame left around which doesn't get cleaned up. This means that
> python part of the PyQt object isn't deleted until the end of the
> (the C++ is, leading to the nasty exception about the C++ object not 
> existing).
> This wouldn't be so bad because you shouldn't leave uncaught exceptions,

> however if you use an exception hook then the same thing happens. You
> up 
> with PyQt objects which never get deleted until the end of the program.
> There's an example program here. Click on the button to create a new
> dialog. 
> If you close the dialog, __del__ gets called and prints a message. If
> click on the exception button in the dialog first, __del__ never gets 
> called.
> You can insert gc.get_referrers to see the reference to the dialog
> to be in a frame object.
> I assume this is a PyQt bug as I can't replicate it with pure Python,
> it's not simple to reproduce.

Isn't this the normal behaviour? The stack frame is part of the traceback
of the exception. It will stay around until it is replaced by another

If you add a second button to the first dialog that also raises an
exception, you should see that the __del__ method is called when the second
exception is raised. There should only ever be one stack frame hanging


More information about the PyQt mailing list