[PyQt] PyQt5: missing GIL release in QDBusConnection::connect

Phil Thompson phil at riverbankcomputing.com
Tue Feb 27 22:14:45 GMT 2018



> On 27 Feb 2018, at 8:17 pm, Christian Häggström <kalvdans at gmail.com> wrote:
> 
> Hi PyQt mailing list,
> 
> I have encountered a hang when I try to connect to dbus via PyQt5. This is my code:
> 
> import sys
> from PyQt5.QtCore import pyqtSlot, QObject
> from PyQt5.QtDBus import QDBusConnection, QDBusMessage
> from PyQt5.QtWidgets import QApplication
> 
> class Foo(QObject):
>    @pyqtSlot(QDBusMessage)
>    def InterfacesAdded(self, msg):
>        pass
> 
> app = QApplication(sys.argv)
> conn = QDBusConnection.systemBus()
> foo = Foo()
> conn.connect('org.freedesktop.UDisks2',
>             '/org/freedesktop/UDisks2',
>             'org.freedesktop.DBus.ObjectManager',
>             "InterfacesAdded",
>             foo.InterfacesAdded)
> 
> GDB shows the QDBusConnection thread hanging while acquiring the GIL:
> 
> #0  0x00007fc48b603786 in futex_abstimed_wait_cancelable (private=<optimized out>, abstime=0x7fc47fb426f0, expected=0, futex_word=0xa89488 <gil_cond+40>)
>    at ../sysdeps/unix/sysv/linux/futex-internal.h:205
> #1  __pthread_cond_wait_common (abstime=0x7fc47fb426f0, mutex=0xa89420 <gil_mutex>, cond=0xa89460 <gil_cond>) at pthread_cond_wait.c:539
> #2  __pthread_cond_timedwait (cond=cond at entry=0xa89460 <gil_cond>, mutex=mutex at entry=0xa89420 <gil_mutex>, abstime=abstime at entry=0x7fc47fb426f0) at pthread_cond_wait.c:667
> #3  0x000000000054e3ac in PyCOND_TIMEDWAIT (cond=0xa89460 <gil_cond>, mut=0xa89420 <gil_mutex>, us=<optimized out>) at ../Python/condvar.h:103
> #4  take_gil (tstate=tstate at entry=0x7fc478013010) at ../Python/ceval_gil.h:224
> #5  0x000000000054fb39 in PyEval_RestoreThread (tstate=tstate at entry=0x7fc478013010) at ../Python/ceval.c:368
> #6  0x00000000004295d2 in PyGILState_Ensure () at ../Python/pystate.c:893
> #7  0x00007fc485477b84 in sip_api_is_py_method (gil=0x7fc47fb42804, pymc=0x10d0729 "", sipSelf=0x7fc484f2adc8, cname=0x0, mname=0x7fc485195e39 <sipStrings_QtCore+23353> "connectNotify")
>    at siplib.c:8294
> #8  0x00007fc4850b9999 in sipQObject::connectNotify (this=0x10d0710, a0=...) at ./build-3.6/QtCore/sipQtCorepart8.cpp:23164
> #9  0x00007fc489b6dce2 in QObjectPrivate::connectImpl(QObject const*, int, QObject const*, void**, QtPrivate::QSlotObjectBase*, Qt::ConnectionType, int const*, QMetaObject const*) ()
>   from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
> #10 0x00007fc489b6deb2 in QObject::connectImpl(QObject const*, void**, QObject const*, void**, QtPrivate::QSlotObjectBase*, Qt::ConnectionType, int const*, QMetaObject const*) ()
>   from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
> 
> These are my installed versions on Ubuntu artful:
> 
> python3.6          3.6.3-1ubuntu1
> python3-pyqt5      5.7+dfsg-6
> libqt5core5a:amd64 5.9.1+dfsg-10ubuntu1
> libqt5dbus5:amd64  5.9.1+dfsg-10ubuntu1
> 
> I read that only select functions will release the GIL in PyQt5 and maybe QDBusConnection::connect isn't one of them?

Should be fixed in tonight's snapshot.

Thanks,
Phil


More information about the PyQt mailing list