Skip to content

Commit 3f3b06f

Browse files
Copilotshauneccles
andcommitted
Add documentation for release_gil parameter in README
Added a new "Multi-threading and GIL Control" section explaining: - The release_gil parameter and its three modes (None/auto, True, False) - When to use each mode for optimal performance - Examples for resample(), Resampler.process(), and CallbackResampler.read() Co-authored-by: shauneccles <21007065+shauneccles@users.noreply.github.com>
1 parent 7b49c8c commit 3f3b06f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ assert np.allclose(output_data_simple, output_data_full)
5858

5959
See `samplerate.resample`, `samplerate.Resampler`, and `samplerate.CallbackResampler` in the API documentation for details.
6060

61+
## Multi-threading and GIL Control
62+
63+
All resampling methods support a `release_gil` parameter that controls Python's Global Interpreter Lock (GIL) during resampling operations. This is useful for optimizing performance in different scenarios:
64+
65+
``` python
66+
import samplerate
67+
68+
# Default: "auto" mode - releases GIL only for large data (>= 1000 frames)
69+
# Balances single-threaded performance with multi-threading capability
70+
output = samplerate.resample(input_data, ratio)
71+
72+
# Force GIL release - best for multi-threaded applications
73+
# Allows other Python threads to run during resampling
74+
output = samplerate.resample(input_data, ratio, release_gil=True)
75+
76+
# Disable GIL release - best for single-threaded applications with small data
77+
# Avoids the ~1-5µs overhead of GIL release/acquire
78+
output = samplerate.resample(input_data, ratio, release_gil=False)
79+
```
80+
81+
The same parameter is available on `Resampler.process()` and `CallbackResampler.read()`:
82+
83+
``` python
84+
resampler = samplerate.Resampler('sinc_best', channels=1)
85+
output = resampler.process(input_data, ratio, release_gil=True)
86+
```
87+
6188
## See also
6289

6390
- [scikits.samplerate](https://pypi.python.org/pypi/scikits.samplerate) implements only the Simple API and uses [Cython](http://cython.org/) for extern calls. The resample function of scikits.samplerate and this package share the same function signature for compatiblity.

0 commit comments

Comments
 (0)