mpickering / pyReaderWriterLock

Python 3 implementation of the Readers-writers problem

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reader Writer Lock

A python implementation of the three Reader-Writer problems.

Build Status BugTracker pyReaderWriterLock_repo_star

Python Version Pypi Version

Code size in bytes License

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.

The tests can be initiated by doing

./rwlock_test.py

Build

This project uses the BUILDME interface, you may therefore build the project by simply doing:

./BUILDME

Contribute

You are the welcome to contribute (Welcome in the open source world):

  • Bug/Suggestion/Comment

Contact

About

Python 3 implementation of the Readers-writers problem

License:Other


Languages

Language:Python 95.1%Language:Makefile 4.8%Language:Batchfile 0.1%