dofuuz / python-soxr

Fast and high quality sample-rate conversion library for Python
Other
78 stars 6 forks source link

Release GIL while resampling #5

Closed I-love-study closed 2 years ago

I-love-study commented 2 years ago

Hi, it's nice to see there's a convenient library to use soxr in python. But it seems that it will not release GIL while resampling. Can it release GIL while resampling?

dofuuz commented 2 years ago

@I-love-study Can you provide some code to test GIL?

I-love-study commented 2 years ago

I use the code like this

import asyncio
from time import time
import soundfile
import soxr

data, samplerate = soundfile.read("test.flac")

def resample():
    soxr.resample(data, samplerate, 24000)

async def th_resample():
    await asyncio.to_thread(resample)

async def main():
    t = time()
    await asyncio.gather(th_resample())
    print(time() - t)

    t = time()
    await asyncio.gather(th_resample(), th_resample())
    print(time() - t)

    t = time()
    await asyncio.gather(th_resample(), th_resample(), th_resample())
    print(time() - t)

    t = time()
    await asyncio.gather(th_resample(), th_resample(), th_resample(), th_resample())
    print(time() - t)

    t = time()
    await asyncio.gather(th_resample(), th_resample(), th_resample(), th_resample(), th_resample())
    print(time() - t)

asyncio.run(main())
dofuuz commented 2 years ago

@I-love-study Can you confirm and test fix with v0.3.0a2?

pip install soxr==0.3.0a2
I-love-study commented 2 years ago

Yes, it's working.

dofuuz commented 2 years ago

c90df4c