A python implementation of the three Reader-Writer problems.
Project description
Reader Writer Lock
==================
**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](https://wikipedia.org/wiki/Readers–writers_problem).
# 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*)
```python
import rwlock
a = rwlock.RWLockRead()
```
**Writer priority** (*aka Second readers-writers problem*)
```python
import rwlock
a = rwlock.RWLockWrite()
```
**Fair priority** (*aka Third readers-writers problem*)
```python
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](tests/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
```bash
./rwlock_test.py
```
# Build
This project use the [BUILDME](https://github.com/elarivie/BUILDME) interface, you may therefore build the project by simply doing:
```bash
./BUILDME
```
Contribute
----
You are the welcome to contribute (Welcome in the open source world):
* Bug/Suggestion/Comment
Contact
----
* Project: [GitHub](https://github.com/elarivie/pyReaderWriterLock)
* Éric Larivière <ericlariviere@hotmail.com>
==================
**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](https://wikipedia.org/wiki/Readers–writers_problem).
# 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*)
```python
import rwlock
a = rwlock.RWLockRead()
```
**Writer priority** (*aka Second readers-writers problem*)
```python
import rwlock
a = rwlock.RWLockWrite()
```
**Fair priority** (*aka Third readers-writers problem*)
```python
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](tests/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
```bash
./rwlock_test.py
```
# Build
This project use the [BUILDME](https://github.com/elarivie/BUILDME) interface, you may therefore build the project by simply doing:
```bash
./BUILDME
```
Contribute
----
You are the welcome to contribute (Welcome in the open source world):
* Bug/Suggestion/Comment
Contact
----
* Project: [GitHub](https://github.com/elarivie/pyReaderWriterLock)
* É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
readerwriterlock-1.0.0.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for readerwriterlock-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ecab0e9ae5dddef36c038151f75cc763bb0172e38db369ae758aca2ffcfd6c8 |
|
MD5 | ce10054f7725e79a6a7732d213beb54a |
|
BLAKE2b-256 | cf79d2f88c5487c2987933bf60f28c5c05cb78511d3b87e7c2e18c720a5fb66b |