QAudioOutput constructor hangs in PyQt6

Phil Thompson phil at riverbankcomputing.com
Sat Apr 11 17:27:15 BST 2026


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.

Phil

On 11/04/2026 15:50, ekhumoro wrote:
> On 11/04/2026 10:56, Phil Thompson wrote:
>> It's not clear from your description as to exactly what's happening 
>> and what you expect to happen. Also your Python and C++ code are not 
>> equivalent as they interact with the event loop in different ways.
> Sorry, I forgot to add the output. The examples *are* equivalent. The
> code is just factored slightly differently so the relevant part can be
> run with a timer in Python (since without that it will hang). I have
> added the output from my Linux system below. Please note that the
> warning message does not affect the *playing* of audio in any way.
> With the examples that don't hang, the audio plays just fine. However,
> I do suspect that there may be a problem with *reading* that message
> in the PyQt6 examples. Without the timer (or *with* the
> qt-message-handler), it seems that the PyQt6 code somehow gets stuck
> waiting for the output to be read, whereas the C++ example is totally
> unaffected.
> 
> #####
> 
> C++ - no timer / with qt-message-handler (this works exactly as 
> expected):
> 
>     $ ./test
>     INFO: Using Qt multimedia with FFmpeg version n8.1 GPL version 3 or 
> later
> 
>     DEBUG: creating audio output...
> 
>     WARNING: spaVisitChoice: parse error ... <elided>
> 
>     DEBUG: audio output created
> 
>     INFO: cancelled: no source file provided
> 
> #####
> 
> Python - without timer / without qt-message-handler (this hangs):
> 
>     $ ./test_pyqt.py
>     Press Ctrl+C to quit
> 
>     qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version n8.1
> GPL version 3 or later
>     creating audio output...
>     ^C
> 
> #####
> 
> Python - with single-shot timer / without qt-message-handler (this
> does not hang):
> 
>     Press Ctrl+C to quit
> 
>     qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version n8.1
> GPL version 3 or later
>     creating audio output...
>     spaVisitChoice: parse error ... <elided>
>     audio output created
>     DEBUG: cancelled: no audio source provided
> 
> #####
> 
> Python - with single-shot timer / with qt-message-handler (this hangs):
> 
>     Press Ctrl+C to quit
> 
>     INFO: Using Qt multimedia with FFmpeg version n8.1 GPL version 3 or 
> later
> 
>     DEBUG: creating audio output...
> 
>     ^C
> 
> #####
> 
> It may be that there's something odd about that specific warning
> message, which is quite long and displayed all on one line in the
> terminal:
> 
>     spaVisitChoice: parse error "Object: size 144, type
> Spa:Pod:Object:Param:Format (262147), id Spa:Enum:ParamId:EnumFormat
> (3)" "  Prop: key Spa:Pod:Object:Param:Format:mediaType (1), flags
> 00000000" "    Id 1  (Spa:Enum:MediaType:audio)" "  Prop: key
> Spa:Pod:Object:Param:Format:mediaSubtype (2), flags 00000000" "    Id
> 3  (Spa:Enum:MediaSubtype:iec958)" "  Prop: key
> Spa:Pod:Object:Param:Format:Audio:iec958Codec (65542), flags 00000000"
> "   Choice: type Spa:Enum:Choice:Enum, flags 00000000 24 4" "      Id
> 1        (Spa:Enum:AudioIEC958Codec:PCM)" "      Id 1
> (Spa:Enum:AudioIEC958Codec:PCM)" "  Prop: key
> Spa:Pod:Object:Param:Format:Audio:rate (65539), flags 00000000" "
> Choice: type Spa:Enum:Choice:Range, flags 00000000 28 4" "      Int
> 48000" "      Int 32000" "      Int 48000"
> 
> The main reason for installing a qt message handler is to prevent any
> unwanted messages like these being shown to the user. I can work
> around the issue by uninstalling the message-handler before creating
> the audio-output object and then reinstalling it again afterwards.
> However, this requires additional low-level code to redirect
> stdout/stderr whilst the audio-object is being created, which is far
> from ideal.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug2.py
Type: text/x-script.python
Size: 1441 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20260411/869de0f4/attachment.bin>


More information about the PyQt mailing list