Skip to main content

RwLock: Reader-Writer lock

Project description

Python Version Pypi Version Code size in bytes

Upload Python Package



RwLock: Reader-Writer lock


We can simply protect a shared resource by a lock. But the performance is not good because each reader should run one-by-one.

A Reader-Writer lock can improve the performance by let readers running simultaneously.

By the way, a writer should wait until all readers done. In a frequently read situation, a new reader after the writer can also increase the read count, let read count never decrease to 0. This will starve writer.


  1. Let readers running simultaneously.
  2. Exclude "multiple readers" and each writer.
  3. provide a flag "write_first" to prevent starve writer.

After 1.6.0, RwLock can support multi-thread(default) and multi-process. For multi-process scenario, use rwlock = RwLock(cross_process=True)

Version control

  • cy-rwlock XX.YY.ZZ
    1. XX.YY match the latest git tag.
    2. ZZ will increase automatically when new commit appear in master branch.
    3. XX: Update when change architecture
    4. YY: Update when add or modify some features
    5. ZZ: Update when bugfix or minor changes.



  1. pip install cy_rwlock
  2. download latest version from


from rwlock import RwLock

rwlock = RwLock()

# read...

# OR
with rwlock.lock_r():
    # read...

# write...

# OR
with rwlock.lock_w():
    # write...


  • local(windows)
    • run scripts\run.bat
  • github
    • auto run when push


  • PyPI version
    • convertd from git tag
  • local(windows)
    • run scripts\deploy.bat
  • github -> PyPI
    • When release in github

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cy_rwlock-1.9.1.tar.gz (4.7 kB view hashes)

Uploaded source

Built Distribution

cy_rwlock-1.9.1-py3-none-any.whl (7.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page