QAudioOutput constructor hangs in PyQt6

Phil Thompson phil at riverbankcomputing.com
Sun Apr 12 10:14:26 BST 2026


On 11/04/2026 21:44, ekhumoro wrote:
> On 11/04/2026 18:49, ekhumoro wrote:
>> On 11/04/2026 17:27, Phil Thompson wrote:
>>> The attached is a version of your Python code modified so that it 
>>> *is* the equivalent of the C++ code. It does not hang.
>>> 
>>> Your original code enters the event loop unconditionally, ie. when 
>>> there is no audio to play
>> 
>> Actually, it doesn't enter the event loop *at all*, because it hangs 
>> when creating the audio output object. Your version of the code also 
>> hangs on my system, for exactly the same reason. The critical section 
>> is this:
>> 
>>      qDebug('creating audio output...')
>>      audio = QAudioOutput()              # <-- hangs here
>>      qDebug('audio output created')
>> 
>> Given the way `qInstallMessageHandler` works, I assume PyQt6 must 
>> doing *something* different - otherwise it's hard to understand why 
>> the C++ example never hangs on my system. The *only* difference seems 
>> to be the handling of that specific warning message.
> 
> After some further investigation, I discovered that the specific
> warning message that seems to cause the hang comes from within Qt6
> itself, as part of its pipewire support. The debug print is in
> qtmultimedia/src/multimedia/pipewire/qpipewire_spa_pod_parser_support_p.h,
> in the spaVisitChoice function around line 140:
> 
>     qWarning() << "spaVisitChoice: parse error" << pod;
> 
> The pod variable is a complex nested struct type defined by pipewire
> (see: https://docs.pipewire.org/page_spa_pod.html). Qt6 implements a
> special QDebug operator to handle this type via a QtSpaDebugContext,
> which can be found in
> qtmultimedia/src/multimedia/pipewire/qpipewire_support.cpp. Is there
> something here which could cause PyQt6 problems?
> 
> Most Linux systems seem to use pipewire these days (rather than
> pulseaudio), and Qt6 recommends it (see:
> https://doc.qt.io/qt-6/qtmultimedia-linux.html). Presumably there must
> be some other people using pipewire on Linux who should be able to
> reproduce my PyQt6 hang behaviour, although it's not clear to me yet
> what's causing the parse error.

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.

Phil


More information about the PyQt mailing list