Skip to content

Commit d026abe

Browse files
authored
Merge pull request #486 from ngoldbaum/thread-safety-docs
Add readme section on thread safety
2 parents 971db39 + 1688c02 commit d026abe

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

README.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,25 @@ and `bitrate_mode` is 'VARIABLE', 'CONSTANT', or 'AVERAGE'.
261261
# minimum mp3 compression results in 3.5 Mb file
262262
sf.write('min_compression_vbr.mp3', data, samplerate, bitrate_mode='VARIABLE', compression_level=0)
263263
264+
Thread Safety
265+
-------------
266+
267+
The ``soundfile`` module is a thin wrapper around the low-level ``libsndfile`` C
268+
library. As such, ``soundfile`` provides the same thread safety guarantees as
269+
the underlying C library. See `this libsndfile issue
270+
<https://github.com/libsndfile/libsndfile/issues/279>`_ for more details.
271+
272+
In short, multithreaded use is safe as long as handles for readers or writers
273+
are not shared between threads. It is safe to concurrently open and read the
274+
same file through unique per-thread handles. It is not safe to concurrently
275+
write to the same file or share reader or writer handles. You may see garbage
276+
results or crashes if you do this.
277+
278+
See the advice in the Free-threaded Python guide on `thread-safe Python
279+
programming
280+
<https://py-free-threading.github.io/porting/#multithreaded-python-programming>`_
281+
for suggestions on how to synchronize access to a thread-unsafe object.
282+
264283
Known Issues
265284
------------
266285

0 commit comments

Comments
 (0)