[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] Fwd: [BUG] Use of QSGThreadedRenderLoop in QML can lead to deadlock (PyQt 5.4.2)
From:       Vladimir Rutsky <rutsky.vladimir () gmail ! com>
Date:       2015-06-19 11:27:35
Message-ID: CAMwdcVYUk8NrWYqaCPBzc-JxHQCydC7uKKw4ko6hcc9GOK38eg () mail ! gmail ! com
[Download RAW message or body]

Forgot to add mailing list in CC.


---------- Forwarded message ----------
From: Vladimir Rutsky <rutsky.vladimir@gmail.com>
Date: Fri, Jun 19, 2015 at 2:22 PM
Subject: Re: [PyQt] [BUG] Use of QSGThreadedRenderLoop in QML can lead
to deadlock (PyQt 5.4.2)
To: Phil Thompson <phil@riverbankcomputing.com>


On Thu, Jun 18, 2015 at 11:20 PM, Phil Thompson
<phil@riverbankcomputing.com> wrote:
> On 18/06/2015 8:06 pm, Vladimir Rutsky wrote:
>>
>> 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".
>
>
> I've added /ReleaseGIL/ to all the QQuickWindow and QQuickView methods that
> seem to depend on the internal mutex.
>
> Phil
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Thanks, Phil, this fixed deadlock in the example.
Still my application hangs if render loop is destroyed from
QApplication destructor (not from QQuickView as was in the example).
I have updated example that reproduces deadlock on recent nightly
build (97ce4458a5c1):
https://gist.github.com/rutsky/d6332e3354972997e938
(or you can just comment explicit "del view" in previous example).


Regards,

Vladimir Rutsky
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic