QAudioOutput constructor hangs in PyQt6

Phil Thompson phil at riverbankcomputing.com
Sun Apr 12 14:38:09 BST 2026


On 12/04/2026 13:50, ekhumoro wrote:
> On 12/04/2026 10:14, Phil Thompson wrote:
>> I was able to reproduce the problem on Linux. Usually when something 
>> hangs it is due to a deadlock between the GIL and some hidden mutex. 
>> Releasing the GIL for the QAudioOutput ctors seems to fix the problem. 
>> Your code still hangs of course, but in a different place.
> 
> Thanks Phil - that's great to hear. Just to be clear: does your fix
> apply to the Qt message-handler issue as well? I'm hoping your
> solution can also deal with this minimal test-case:
> 
> 
>     import sys, signal
>     signal.signal(signal.SIGINT, signal.SIG_DFL)
>     from PyQt6.QtCore import QTimer, qInstallMessageHandler
>     from PyQt6.QtWidgets import QApplication
>     from PyQt6.QtMultimedia import QAudioOutput
> 
>     app = QApplication(sys.argv)
>     qInstallMessageHandler(lambda mode, ctx, msg: print(msg))
>     QTimer.singleShot(100, lambda: QAudioOutput() and 
> print('\nSUCCESS!\n'))
>     app.exec()
> 
> For me, this only hangs (i.e. does not print 'SUCCESS!') when the
> message-handler is installed. I assume using a timer is just a
> different way to bypass the deadlock - but that the PyQt
> message-handler wrapper then reacquires the GIL later on when the Qt
> debug message is encountered, thus reinstating the problem.

This prints SUCCESS! and hangs whether or not the message handler is 
installed.

Phil


More information about the PyQt mailing list