[PyQt] Segfault: QGraphicsView, cyclic references, and threads
phil at riverbankcomputing.com
Mon Mar 28 12:57:43 BST 2011
On Sun, 27 Mar 2011 22:29:38 -0400, Luke Campagnola
<lcampagn at email.unc.edu> wrote:
> Greetings All-Knowing PyQters,
> I have a strange bug that's causing segmentation faults in my program. I
> have identified some of the key contributors to the bug and a
> but I would love for someone to explain what causes the crash so I can
> similar problems in the future.
> Here are the things required to cause the crash:
> 1) Repeatedly creating and deleting a GraphicsView and GraphicsItem
> 2) The each GraphicsItem has a reference to the GraphicsView it is shown
> 3) Having a second thread running and actively working
> Usually a segmentation fault will occur after roughly 10-1000
> cycles. Taking away any of these components prevents the crash. The
> thread does not have to be doing anything specific and does not even
> be a QThread; it just has to be doing _something_. If the Item has a
> to its View, there is no crash (and this is a perfectly acceptable
> I have attached a GDB backtrace and a short script demonstrating the
> When I run the script on my system (Ubuntu 10.04, PyQt 4.7.2), about
> the time it causes a segfault, and the rest of the time it just freezes.
> I've also tested the script on WinXp with PyQt 4.8.3 and 4.5.4, with
> results. PySide does not have the bug, so I suspect it is not a Qt
> Any advice would be greatly appreciated!
PyQt keeps track of certain types of object that are known to cause
problems if they are garbage collected before the QApplication -
QGraphicsScene is one of these. It seems that QObjectCleanupHandler has
problems in a threaded application.
Fixed (or at least worked around) in tonight's PyQt snapshot.
More information about the PyQt