[PyQt] [BUG] Use of QSGThreadedRenderLoop in QML can lead to deadlock (PyQt 5.4.2)

Vladimir Rutsky rutsky.vladimir at gmail.com
Thu Jun 18 20:06:14 BST 2015


Hello,

I described this issue in comment to other bug report
(http://www.riverbankcomputing.com/pipermail/pyqt/2015-June/036048.html),
and now want to open separate thread for it, since it's not just
"application hangs on exit", but real deadlock issue that can occur in
many cases of QML usage (e.g. when window is shown or hidden).

The deadlock is reproduced when QML rendering is done using threaded
render loop (QSGThreadedRenderLoop), which is default on modern
GNU/Linux systems (Windows always use single threaded rendering in Qt
5.4).

As I understand from GDB stack traces, the deadlock happens in the
following way.
Sometimes QQuickView starting to wait rendering thread for some
operation (using mutex). Rendering thread can request operation that
is implemented in Python code, this operation will try to lock Python
GIL in rendering thread, but GIL is not released in main thread, and
never be, since main thread waits rendering thread in Qt.

One of the situations in which QQuickView waits rendering thread is
when QQuickView is being destroyed: it waits while rendering thread
will release all resources.
This case can be easily reproduced on GNU/Linux in this example:
https://gist.github.com/rutsky/d6332e3354972997e938
The example also have GDB stack traces at the moment when application
hanged on exit.

Workaround for this issue is to force Qt to use single threaded
rendering by setting environment variable QSG_RENDER_LOOP to "basic".

Regards,

Vladimir Rutsky


More information about the PyQt mailing list