Skip to content

Commit e84be46

Browse files
committed
docs: better call out temporally overlapping usage is not allowed
Related to #182.
1 parent f9103dd commit e84be46

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

docs/api_usage.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ There is potential for long pauses as data is read or written from the
8888
underlying stream (say from interacting with a filesystem or network). This
8989
could add considerable overhead.
9090

91-
Thread Safety
92-
=============
91+
Thread and Object Reuse Safety
92+
==============================
93+
94+
Unless stated otherwise, ``ZstdCompressor`` and ``ZstdDecompressor`` instances
95+
cannot be used for temporally overlapping (de)compression operations. i.e.
96+
if you start a (de)compression operation on an instance or a helper object
97+
derived from it, it isn't safe to start another (de)compression operation
98+
from the same instance until the first one has finished.
9399

94100
``ZstdCompressor`` and ``ZstdDecompressor`` instances have no guarantees
95101
about thread safety. Do not operate on the same ``ZstdCompressor`` and

zstandard/backend_cffi.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,16 @@ class ZstdCompressor(object):
17511751
``write_checksum``, ``write_content_size``, ``write_dict_id``, and
17521752
``threads``.
17531753
1754+
Assume that each ``ZstdCompressor`` instance can only handle a single
1755+
logical compression operation at the same time. i.e. if you call a method
1756+
like ``stream_reader()`` to obtain multiple objects derived from the same
1757+
``ZstdCompressor`` instance and attempt to use them simultaneously, errors
1758+
will likely occur.
1759+
1760+
If you need to perform multiple logical compression operations and you
1761+
can't guarantee those operations are temporally non-overlapping, you need
1762+
to obtain multiple ``ZstdCompressor`` instances.
1763+
17541764
Unless specified otherwise, assume that no two methods of
17551765
``ZstdCompressor`` instances can be called from multiple Python
17561766
threads simultaneously. In other words, assume instances are not thread safe
@@ -3645,6 +3655,16 @@ class ZstdDecompressor(object):
36453655
The interface of this class is very similar to
36463656
:py:class:`zstandard.ZstdCompressor` (by design).
36473657
3658+
Assume that each ``ZstdDecompressor`` instance can only handle a single
3659+
logical compression operation at the same time. i.e. if you call a method
3660+
like ``decompressobj()`` to obtain multiple objects derived from the same
3661+
``ZstdDecompressor`` instance and attempt to use them simultaneously, errors
3662+
will likely occur.
3663+
3664+
If you need to perform multiple logical decompression operations and you
3665+
can't guarantee those operations are temporally non-overlapping, you need
3666+
to obtain multiple ``ZstdDecompressor`` instances.
3667+
36483668
Unless specified otherwise, assume that no two methods of
36493669
``ZstdDecompressor`` instances can be called from multiple Python
36503670
threads simultaneously. In other words, assume instances are not thread safe

0 commit comments

Comments
 (0)