python-soundfile
python-soundfile copied to clipboard
Stack Overflow while writing OGG
If write long frames to ogg, python will crash without any traceback or info. After faulthandler enabled, it will give "Windows fatal exception: stack overflow" Environments: Windows 10, Python 3.10.8
import faulthandler
import soundfile
import numpy as np
faulthandler.enable()
def work():
f = soundfile.SoundFile("random.ogg", "w", 44100, 1)
data = np.random.randn(600000)
f.write(data)
work()
Oddly, while reduced to 500000, it will run successfully probabilistically or give "access violation".
While python Crashed, the output ogg truncated at 4KB.
For the stack limit of Windows dll call, a solution is to run in a new Thread.
import threading
threading.stack_size(16777216)
t = threading.Thread(target=work)
t.start()
t.join()
I can't confirm whether other problems related to ogg write crashes are also this reason. I think it is possible to add instructions in the documentation or provide other thread wrapping methods.
Thank you for the bug report. However, I'm afraid you'll have to create the bug report in libsndfile, the C library soundfile is built upon. Segfaults are not generally caused by soundfile, but usually somewhere in the OGG decoder inside libsndfile.