[PyQt] Deadlock in QPyQmlObjectProxy::disconnectNotify

Arjen Hiemstra a.hiemstra at ultimaker.com
Thu Mar 10 19:18:11 GMT 2016


Hi,

For some time now, we have run into a rather nasty deadlock when certain QML 
UI items are destroyed. It took me a while to find a minimal example where it 
happens but attached is some Python code that will deadlock on my machine 
within a few seconds after starting it. The equivalent C++ code (also 
attached) does not deadlock.

This happens on several machines, one of them running Arch using Qt 5.5.1,  
PyQt 5.5.1 and Python 3.5.1. It also happens on Mac OSX using Python 3.4, PyQt 
5.4 and Qt 5.5.1 and Windows using the packages provided on the PyQt site.

The deadlock happens in the destructor of QPyQmlObjectProxy, which tries to 
disconnect from a signal of an object that is being destroyed. The backtrace 
is as follows:

#0  0x00007ffff74307f9 in syscall () from /usr/lib/libc.so.6
#1  0x00007ffff5d07d60 in QBasicMutex::lockInternal() () from /usr/lib/
libQt5Core.so.5
#2  0x00007ffff5d07e17 in QMutex::lock() () from /usr/lib/libQt5Core.so.5
#3  0x00007ffff5effead in ?? () from /usr/lib/libQt5Core.so.5
#4  0x00007ffff5ef945d in ?? () from /usr/lib/libQt5Core.so.5
#5  0x00007ffff5efa38b in QObject::disconnect(QObject const*, char const*, 
QObject const*, char const*) () from /usr/lib/libQt5Core.so.5
#6  0x00007ffff16676ed in QPyQmlObjectProxy::disconnectNotify(QMetaMethod 
const&) () from /usr/lib/python3.5/site-packages/PyQt5/QtQml.so
#7  0x00007ffff5eff01b in QObject::~QObject() () from /usr/lib/libQt5Core.so.5
#8  0x00007ffff12c57e8 in QQmlDelegateModel::~QQmlDelegateModel() () from /
usr/lib/libQt5Qml.so.5
#9  0x00007ffff12c5889 in QQmlDelegateModel::~QQmlDelegateModel() () from /
usr/lib/libQt5Qml.so.5
#10 0x00007fffe9d6373a in QQuickItemView::~QQuickItemView() () from /usr/lib/
libQt5Quick.so.5
#11 0x00007fffe9c8fbb6 in ?? () from /usr/lib/libQt5Quick.so.5
#12 0x00007ffff5ef8378 in QObject::event(QEvent*) () from /usr/lib/
libQt5Core.so.5
#13 0x00007fffe9c71b4b in QQuickItem::event(QEvent*) () from /usr/lib/
libQt5Quick.so.5
#14 0x00007fffef332124 in QApplicationPrivate::notify_helper(QObject*, 
QEvent*) () from /usr/lib/libQt5Widgets.so.5
#15 0x00007fffef336f78 in QApplication::notify(QObject*, QEvent*) () from /
usr/lib/libQt5Widgets.so.5
#16 0x00007fffefe4cffe in sipQApplication::notify(QObject*, QEvent*) () from /
usr/lib/python3.5/site-packages/PyQt5/QtWidgets.so
#17 0x00007ffff5ec903a in QCoreApplication::notifyInternal2(QObject*, QEvent*) 
() from /usr/lib/libQt5Core.so.5
#18 0x00007ffff5ecbbc5 in QCoreApplicationPrivate::sendPostedEvents(QObject*, 
int, QThreadData*) () from /usr/lib/libQt5Core.so.5
#19 0x00007ffff5f21113 in ?? () from /usr/lib/libQt5Core.so.5
#20 0x00007ffff4993d87 in g_main_context_dispatch () from /usr/lib/
libglib-2.0.so.0
#21 0x00007ffff4993fe0 in ?? () from /usr/lib/libglib-2.0.so.0
#22 0x00007ffff499408c in g_main_context_iteration () from /usr/lib/
libglib-2.0.so.0
#23 0x00007ffff5f2118f in 
QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () 
from /usr/lib/libQt5Core.so.5
#24 0x00007ffff5ec757a in 
QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/
libQt5Core.so.5
#25 0x00007ffff5ed01fc in QCoreApplication::exec() () from /usr/lib/
libQt5Core.so.5
#26 0x00007fffefe4b91b in meth_QApplication_exec_ () from /usr/lib/python3.5/
site-packages/PyQt5/QtWidgets.so
#27 0x00007ffff79baa89 in PyCFunction_Call () from /usr/lib/libpython3.5m.so.
1.0
#28 0x00007ffff7a32a01 in PyEval_EvalFrameEx () from /usr/lib/
libpython3.5m.so.1.0
#29 0x00007ffff7a32d52 in PyEval_EvalFrameEx () from /usr/lib/
libpython3.5m.so.1.0
#30 0x00007ffff7a33df2 in ?? () from /usr/lib/libpython3.5m.so.1.0
#31 0x00007ffff7a33ed3 in PyEval_EvalCodeEx () from /usr/lib/libpython3.5m.so.
1.0
#32 0x00007ffff7a33efb in PyEval_EvalCode () from /usr/lib/libpython3.5m.so.
1.0
#33 0x00007ffff7a53074 in ?? () from /usr/lib/libpython3.5m.so.1.0
#34 0x00007ffff7a55585 in PyRun_FileExFlags () from /usr/lib/libpython3.5m.so.
1.0
#35 0x00007ffff7a556f6 in PyRun_SimpleFileExFlags () from /usr/lib/
libpython3.5m.so.1.0
#36 0x00007ffff7a6c504 in Py_Main () from /usr/lib/libpython3.5m.so.1.0
#37 0x0000000000400af7 in main ()

Output from valgrind --tool=helgrind:

==18804== ----------------------------------------------------------------
==18804== 
==18804== Thread #1: lock order "0x71826E8 before 0x71827E8" violated
==18804== 
==18804== Observed (incorrect) order is: acquisition of lock at 0x71827E8
==18804==    at 0x4C30F44: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-
linux.so)
==18804==    by 0x4C3346C: QMutex::lock() (in /usr/lib/valgrind/
vgpreload_helgrind-amd64-linux.so)
==18804==    by 0x6F6AFB7: QObject::~QObject() (in /usr/lib/libQt5Core.so.
5.5.1)
==18804==    by 0xBB131E7: QQmlDelegateModel::~QQmlDelegateModel() (in /usr/
lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBB13258: QQmlDelegateModel::~QQmlDelegateModel() (in /usr/
lib/libQt5Qml.so.5.5.1)
==18804==    by 0x12AA704B: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x129E9405: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x6F63FEF: QObject::event(QEvent*) (in /usr/lib/libQt5Core.so.
5.5.1)
==18804==    by 0x129CD2CA: QQuickItem::event(QEvent*) (in /usr/lib/
libQt5Quick.so.5.5.1)
==18804==    by 0xD036FCB: QApplicationPrivate::notify_helper(QObject*, 
QEvent*) (in /usr/lib/libQt5Widgets.so.5.5.1)
==18804==    by 0xD03C4A5: QApplication::notify(QObject*, QEvent*) (in /usr/
lib/libQt5Widgets.so.5.5.1)
==18804==    by 0xCB0704D: sipQApplication::notify(QObject*, QEvent*) (in /
usr/lib/python3.5/site-packages/PyQt5/QtWidgets.so)
==18804== 
==18804==  followed by a later acquisition of lock at 0x71826E8
==18804==    at 0x4C3137B: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-
linux.so)
==18804==    by 0x4C334AE: QMutex::tryLock(int) (in /usr/lib/valgrind/
vgpreload_helgrind-amd64-linux.so)
==18804==    by 0x6F6B099: QObject::~QObject() (in /usr/lib/libQt5Core.so.
5.5.1)
==18804==    by 0xBB131E7: QQmlDelegateModel::~QQmlDelegateModel() (in /usr/
lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBB13258: QQmlDelegateModel::~QQmlDelegateModel() (in /usr/
lib/libQt5Qml.so.5.5.1)
==18804==    by 0x12AA704B: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x129E9405: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x6F63FEF: QObject::event(QEvent*) (in /usr/lib/libQt5Core.so.
5.5.1)
==18804==    by 0x129CD2CA: QQuickItem::event(QEvent*) (in /usr/lib/
libQt5Quick.so.5.5.1)
==18804==    by 0xD036FCB: QApplicationPrivate::notify_helper(QObject*, 
QEvent*) (in /usr/lib/libQt5Widgets.so.5.5.1)
==18804==    by 0xD03C4A5: QApplication::notify(QObject*, QEvent*) (in /usr/
lib/libQt5Widgets.so.5.5.1)
==18804==    by 0xCB0704D: sipQApplication::notify(QObject*, QEvent*) (in /
usr/lib/python3.5/site-packages/PyQt5/QtWidgets.so)
==18804== 
==18804== Required order was established by acquisition of lock at 0x71826E8
==18804==    at 0x4C30F44: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-
linux.so)
==18804==    by 0x4C3346C: QMutex::lock() (in /usr/lib/valgrind/
vgpreload_helgrind-amd64-linux.so)
==18804==    by 0x6F65A34: ??? (in /usr/lib/libQt5Core.so.5.5.1)
==18804==    by 0x6F69F0A: QObject::connect(QObject const*, char const*, 
QObject const*, char const*, Qt::ConnectionType) (in /usr/lib/libQt5Core.so.
5.5.1)
==18804==    by 0x12AAE468: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B23934: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B243AA: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B12484: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0xBACEF78: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACF2D7: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACB879: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACC1D9: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804== 
==18804==  followed by a later acquisition of lock at 0x71827E8
==18804==    at 0x4C30F44: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-
linux.so)
==18804==    by 0x4C3346C: QMutex::lock() (in /usr/lib/valgrind/
vgpreload_helgrind-amd64-linux.so)
==18804==    by 0x6F65A46: ??? (in /usr/lib/libQt5Core.so.5.5.1)
==18804==    by 0x6F69F0A: QObject::connect(QObject const*, char const*, 
QObject const*, char const*, Qt::ConnectionType) (in /usr/lib/libQt5Core.so.
5.5.1)
==18804==    by 0x12AAE468: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B23934: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B243AA: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B12484: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0xBACEF78: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACF2D7: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACB879: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACC1D9: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804== 
==18804==  Lock at 0x71826E8 was first observed
==18804==    at 0x4C30F44: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-
linux.so)
==18804==    by 0x4C3346C: QMutex::lock() (in /usr/lib/valgrind/
vgpreload_helgrind-amd64-linux.so)
==18804==    by 0x6F68358: ??? (in /usr/lib/libQt5Core.so.5.5.1)
==18804==    by 0x6F68B12: QMetaObject::connect(QObject const*, int, QObject 
const*, int, int, int*) (in /usr/lib/libQt5Core.so.5.5.1)
==18804==    by 0x12A4C9B4: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12AA6FC8: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12A58BA3: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x129E937F: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0xBA6B3DA: QQmlType::create() const (in /usr/lib/libQt5Qml.so.
5.5.1)
==18804==    by 0xBACCC43: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACD6DE: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBA57BB6: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==  Address 0x71826e8 is in the BSS segment of /usr/lib/libQt5Core.so.
5.5.1
==18804== 
==18804==  Lock at 0x71827E8 was first observed
==18804==    at 0x4C30F44: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-
linux.so)
==18804==    by 0x4C3346C: QMutex::lock() (in /usr/lib/valgrind/
vgpreload_helgrind-amd64-linux.so)
==18804==    by 0x6F66DC9: ??? (in /usr/lib/libQt5Core.so.5.5.1)
==18804==    by 0x6F678FB: QObject::disconnect(QObject const*, char const*, 
QObject const*, char const*) (in /usr/lib/libQt5Core.so.5.5.1)
==18804==    by 0x12AAE20E: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B23934: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B243AA: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0x12B12484: ??? (in /usr/lib/libQt5Quick.so.5.5.1)
==18804==    by 0xBACEF78: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACF2D7: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACB879: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==    by 0xBACC1D9: ??? (in /usr/lib/libQt5Qml.so.5.5.1)
==18804==  Address 0x71827e8 is in the BSS segment of /usr/lib/libQt5Core.so.
5.5.1
==18804== 
==18804==
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyqt_deadlock_cpp.tar.gz
Type: application/x-compressed-tar
Size: 1605 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160310/5e133b18/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyqt_deadlock.py
Type: text/x-python
Size: 1887 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160310/5e133b18/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyqt_deadlock.qml
Type: text/x-qml
Size: 580 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160310/5e133b18/attachment-0003.bin>


More information about the PyQt mailing list