A python implementation of the three Reader-Writer problems.
Project description
A python implementation of the three Reader-Writer problems.
Not only does it implement the reader-writer problems, it is also compliant with the python lock interface which includes support for timeouts.
For reading about the theory behind the reader-writer problems refer to Wikipedia.
Installation
Install the python package readerwriterlock
python3 -m pip install readerwriterlock
Usage
Initialize a new lock base on your access priority need which is going to be use by the threads:
Reader priority (aka First readers-writers problem)
from readerwriterlock import rwlock a = rwlock.RWLockRead()
Writer priority (aka Second readers-writers problem)
from readerwriterlock import rwlock a = rwlock.RWLockWrite()
Fair priority (aka Third readers-writers problem)
from readerwriterlock import rwlock a = rwlock.RWLockFair()
Pythonic usage example
with a.gen_rlock(): #Read stuff with a.gen_wlock(): #Write stuff
Advanced Usage example
b = a.gen_wlock() if b.acquire(blocking=True, timeout=5): #Do stuff b.release()
Live example
Refer to the file rwlock_test.py which can be directly called, it has above 90% line coverage of [rwlock.py](readerwriterlock/rwlock.py).
The tests can be initiated by doing
./rwlock_test.py
Build
This project use the BUILDME interface, you may therefore build the project by simply doing:
./BUILDME
Contribute
You are the welcome to contribute.
Contact
- Project:
- Bug tracker:
- Author:
Éric Larivière ericlariviere@hotmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for readerwriterlock-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e821f8c8c53d7fcdf6d4492c649ada9d6cc4743b38749a964c46dbef7f019e1b |
|
MD5 | 09f70fcb1770782ad49b0fcf14db2cec |
|
BLAKE2b-256 | cad143b00f35495a0103bf37d94de92191a904f47030b00b53da0f9376407487 |