[PyQt] Segfault: QGraphicsView, cyclic references, and threads

Luke Campagnola lcampagn at email.unc.edu
Mon Mar 28 03:29:38 BST 2011


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 workaround,
but I would love for someone to explain what causes the crash so I can avoid
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 in
3) Having a second thread running and actively working

Usually a segmentation fault will occur after roughly 10-1000 create/delete
cycles. Taking away any of these components prevents the crash. The second
thread does not have to be doing anything specific and does not even have to
be a QThread; it just has to be doing _something_. If the Item has a weakref
to its View, there is no crash (and this is a perfectly acceptable
workaround).

I have attached a GDB backtrace and a short script demonstrating the bug.
When I run the script on my system (Ubuntu 10.04, PyQt 4.7.2), about half of
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 similar
results. PySide does not have the bug, so I suspect it is not a Qt issue.

Any advice would be greatly appreciated!

Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110327/8c84a7df/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdb.log
Type: text/x-log
Size: 8834 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110327/8c84a7df/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bugtest.py
Type: text/x-python
Size: 1209 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110327/8c84a7df/attachment.py>


More information about the PyQt mailing list