Open scottnm opened 9 months ago
for additional context, I found another user on reddit who seemed to be experiencing a similar problem (although their repro was via pydub) https://www.reddit.com/r/pythonhelp/comments/17vw5zy/python_is_hard_crashing_with_a_simple_mp3_play/
though if I understand correctly, pydub uses simpleaudio for playback
The cause of the segmentation fault seems to be calling PyMem_Free(*) without acquiring the GIL.
There are two solutions (both of which solved the problem for me). :
PyMem_Malloc(*)
with PyMem_RawMalloc(*)
and PyMem_Free(*)
with PyMem_RawFree(*)
.PyMem_Free(*)
between PyGILState_STATE gstate = PyGILState_Ensure();
and PyGILState_Release(gstate);
.The former solution is probably better.
With the above changes and rebuild I am able to use simpleaudio in Py3.12. https://github.com/cexen/py-simple-audio
pip install -U --force git+https://github.com/cexen/py-simple-audio.git
I am not familiar enough with package development (especially CI and backward compatibility) to know how to make the necessary changes for users in all environments...
@cexen Thanks a lot! I got the same issue and this fixed it!
Yeah this bug renders simpleaudio unusable.
overview
simpleaudio 1.0.4 seems to crash for me when using python 3.12
the same crash does not reproduce in python 3.11
the crash does not appear to be any form of python failure that I can either catch as an exception or intercept with a python debugger
example
Here's the sample code I'm testing with
when run from a python 3.12 environment with simpleaudio 1.0.4, this is the output
here's the same run but from a python 3.11 environment
Repro Environment information