Can't stop execution when coreaudiod restarts. Stale read
I am using examples/signal_processing.py
My system is macos, so I use coreaudio.
When I restart coreaudiod (when running script) by:
sudo launchctl stop com.apple.audio.coreaudiod && sudo launchctl start com.apple.audio.coreaudiod
or simply
sudo killall coreaudiod
process doesn't throw anything and stales in read loop. Throwing exception by myself doesn't help too (it doesn't throw and continues in stale mode).
Same if I delete virtual audio device I used in definition of mixer class.
I think the underlying PortAudio library simply cannot handle changing audio settings.
The API doesn't provide anything to detect such a situation.
Normally, you would call sd._terminate(), then change your audio settings, and afterwards call sd._initialize(). See https://python-sounddevice.readthedocs.io/en/0.4.4/api/expert-mode.html.
Since many years, there have been discussions and plans for a "hotplug" feature, which would probably help in your case. See https://github.com/PortAudio/portaudio/issues/11 and https://github.com/PortAudio/portaudio/wiki/HotPlug.
See also https://github.com/spatialaudio/python-sounddevice/issues/382.
Thank you for your response.
Using sd._terminate() and sd._initialize() seem pretty legit fix for me.
I'll also try using hotplug in future
I also wonder what is the cause of stale condition?
I don't know. You could ask the PortAudio community: http://portaudio.com/contacts.html
I'm closing this because it can only be fixed upstream. A possible work-around is using sd._terminate() and sd._initialize().