skillfed

readerwriterlock

A python implementation of the three Reader-Writer problems.

readerwriterlock v1.0.9 2.7M downloads/30d#2,956 on PyPI104
Permissive license MIT Abandoned released

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 readerwriterlock

uv

uv add readerwriterlock

poetry

poetry add readerwriterlock

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

reader writer lock pythonrwlock synchronizationthread lock priorityconcurrent read write accessfair lock implementationdowngrade write to read lockreader priority lock
concurrencythreadingsynchronization

More Software Development packages