Skip to content

Commit 42cd2c4

Browse files
committed
Clarify thread-safety limitations in shelve module
1 parent eae9d7d commit 42cd2c4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Doc/library/shelve.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,16 @@ Restrictions
134134
the database to refuse updates.
135135

136136
* The :mod:`shelve` module does not support *concurrent* read/write access to
137-
shelved objects. (Multiple simultaneous read accesses are safe.) When a
137+
shelved objects, whether from different programs or different threads within
138+
the same program. (Multiple simultaneous read accesses are safe.) When a
138139
program has a shelf open for writing, no other program should have it open for
139-
reading or writing. Unix file locking can be used to solve this, but this
140-
differs across Unix versions and requires knowledge about the database
140+
reading or writing. Additionally, within a single program, concurrent access
141+
from multiple threads is not supported and may lead to data corruption,
142+
unexpected behavior, or crashes. This affects all writing operations including
143+
assignment, deletion, :meth:`~Shelf.sync`, and :meth:`~Shelf.reorganize`.
144+
Even with :attr:`writeback` set to :const:`True`, thread-safety is not
145+
guaranteed. Unix file locking can be used to solve cross-program concurrency,
146+
but this differs across Unix versions and requires knowledge about the database
141147
implementation used.
142148

143149
* On macOS :mod:`dbm.ndbm` can silently corrupt the database file on updates,

0 commit comments

Comments
 (0)