readerwriterlock
A python implementation of the three Reader-Writer problems.
What it is and what it does
readerwriterlock is a pure-Python implementation of the three classical reader-writer synchronization problems—a concurrency pattern where multiple readers can hold a lock simultaneously, but writers require exclusive access. The package provides six lock classes: three prioritize readers, writers, or fairness respectively, and three downgradable variants that allow atomically converting a write lock to a read lock (with a documented ~20% performance cost). All classes conform to Python's standard threading.Lock interface, including support for timeouts and context managers.
You instantiate a lock class, then call gen_rlock() or gen_wlock() to create reader or writer lock objects that you acquire and release in your code. The choice of class determines scheduling behavior: reader-priority favors read throughput, writer-priority prevents writer starvation, and fair-priority balances both. The package depends only on typing-extensions and has no system-level dependencies.
Use it for:
- Protect a shared cache or in-memory data structure where reads vastly outnumber writes and you want many concurrent readers.
- Implement a fair lock for a resource where both readers and writers must be served without starvation, such as a shared log or configuration store.
- Build a write-heavy system where writer priority prevents reader threads from blocking critical updates indefinitely.
- Use lock downgrading when a thread acquires write access to check-then-update a value, then only needs read access afterward without releasing and re-acquiring.
- Add timeout-based lock acquisition to detect and handle deadlock scenarios in multi-threaded applications.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides reader-writer lock implementations for Python that solve the three classical reader-writer synchronization problems with configurable priority schemes (reader, writer, or fair) and optional lock downgrading.
Yes, if you need a reader-writer lock and are comfortable with an abandoned package. The implementation is marked Production/Stable with no known vulnerabilities and has 104 GitHub stars, suggesting stability. Reader-writer locks are a well-understood pattern unlikely to require frequent updates. However, verify compatibility with your Python version and consider whether the lack of maintenance is acceptable for your use case.
Install
readerwriterlock on PyPI
pip
pip install readerwriterlockuv
uv add readerwriterlockpoetry
poetry add readerwriterlockInstalling readerwriterlock
Before you install
Low install friction with a single pure-Python dependency. However, the package is abandoned—last release was 2021-09-06 with no recent commits. Use only if you need a stable, unchanging implementation and can maintain it yourself if issues arise.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial or private projects with minimal restrictions, provided you include the license notice.
Quickstart
from readerwriterlock import rwlock
a = rwlock.RWLockFairD()
with a.gen_rlock():
# read operation
pass
with a.gen_wlock():
# write operation
pass
Verify before relying
- Whether the implementation has been tested against Python versions beyond 3.9 or if there are known compatibility issues with newer releases.
- Real-world performance characteristics and scalability limits compared to alternatives or standard library threading primitives.
- Whether the ~20% performance cost of downgradable locks applies uniformly across all three priority schemes.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing-extensions |
| Maintenance | abandoned — 1,803 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,657,969/month — #2,956 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: readerwriterlock-1.0.9-py3-none-any.whl
Keywords: rwlock, read-write lock, lock, priority, reader, writer, fair, read, write, thread, synchronize
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
aiorwlockProvides read-write locks for asyncio programs,…
permissive · top 5,000 on PyPI
fastenersProvides cross-platform locks for synchronizing…
permissive · top 5,000 on PyPI
locketLocket provides file-based locks for…
permissive · top 1,000 on PyPI
redlockImplements the RedLock algorithm to provide…
permissive · top 15,000 on PyPI
zc.lockfileProvides portable inter-process locks…
unclear · top 5,000 on PyPI
portalockerPortalocker provides cross-platform file…
permissive · top 1,000 on PyPI
python-dynamodb-lockProvides distributed locking on top of DynamoDB…
permissive · top 15,000 on PyPI
fifolockFifolock provides a low-level building block…
permissive · top 15,000 on PyPI
redlock-pyImplements Redis-based distributed locks using…
permissive · top 15,000 on PyPI
django-pglockProvides Postgres advisory locks, table locks,…
permissive · top 5,000 on PyPI