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.
RwLock:
- Let readers running simultaneously.
- Exclude "multiple readers" and each writer.
- 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)
- cy-rwlock XX.YY.ZZ
- XX.YY match the latest git tag.
- ZZ will increase automatically when new commit appear in master branch.
- XX: Update when change architecture
- YY: Update when add or modify some features
- ZZ: Update when bugfix or minor changes.
pip install cy_rwlock
- download latest version from https://pypi.org/project/cy_rwlock/#files
from rwlock import RwLock
rwlock = RwLock()
### READER
rwlock.acquire_r()
# read...
rwlock.release_r()
# OR
with rwlock.lock_r():
# read...
### WRITER
rwlock.acquire_w()
# write...
rwlock.release_w()
# OR
with rwlock.lock_w():
# write...
- local(windows)
- run
scripts\run.bat
- run
- github
- auto run when push
- PyPI version
- convertd from git tag
- see setup.py: convert_version()
- convertd from git tag
- local(windows)
- run
scripts\deploy.bat
- run
- github -> PyPI
- When release in github