[PyQt] Exceptions and stack frames

Jeremy Sanders jeremy at jeremysanders.net
Thu Aug 19 20:48:46 BST 2010


I have a problem with stack frames hanging around after exceptions in PyQt 
objects.

A particular method on a PyQt object is connected to a signal. This method 
is called because of the signal is raised.

If I get an uncaught exception in that method, then there appears to be a 
stack frame left around which doesn't get cleaned up. This means that the 
python part of the PyQt object isn't deleted until the end of the program 
(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 end 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 you 
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 appears 
to be in a frame object.

I assume this is a PyQt bug as I can't replicate it with pure Python, but 
it's not simple to reproduce.

Jeremy

-- 
http://www.jeremysanders.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 1801 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100819/ac13b413/attachment.py>


More information about the PyQt mailing list