Reader Writer Lock
==================
**A python implementation of a solution for the three Reader-Writer problems.**
[![repo status Active](https://www.repostatus.org/badges/latest/active.svg "repo status Active")](https://www.repostatus.org/#active)
[![Build Status](https://travis-ci.org/elarivie/pyReaderWriterLock.svg?branch=master)](https://travis-ci.org/elarivie/pyReaderWriterLock)
[![Coverage Status](https://codecov.io/gh/elarivie/pyreaderwriterlock/branch/master/graph/badge.svg)](https://codecov.io/gh/elarivie/pyreaderwriterlock)
[![BugTracker](https://img.shields.io/github/issues/elarivie/pyReaderWriterLock.svg)][pyReaderWriterLock_BugTracker]
[![Python Version](https://img.shields.io/pypi/pyversions/readerwriterlock.svg)][python]
[![Pypi Version](https://img.shields.io/pypi/v/readerwriterlock.svg)][pyReaderWriterLock_Pypi]
[![Code size in bytes](https://img.shields.io/github/languages/code-size/elarivie/pyReaderWriterLock.svg)][pyReaderWriterLock_repo]
[![License](https://img.shields.io/pypi/l/readerwriterlock.svg)][pyReaderWriterLock_License]
[![Downloads](https://pepy.tech/badge/readerwriterlock)](https://pepy.tech/project/readerwriterlock)
[![Downloads](https://pepy.tech/badge/readerwriterlock/month)](https://pepy.tech/project/readerwriterlock/month)
[![Downloads](https://pepy.tech/badge/readerwriterlock/week)](https://pepy.tech/project/readerwriterlock/week)
[![pyReaderWriterLock_repo_star](https://img.shields.io/github/stars/elarivie/pyReaderWriterLock.svg?style=social&label=Stars)][pyReaderWriterLock_repo_star]
Not only does it implement the reader-writer problems, it is also compliant with the python [lock interface](https://docs.python.org/3/library/threading.html#threading.Lock) which among others include support for timeout.
For reading about the theory behind the reader-writer problems refer to [Wikipedia](https://wikipedia.org/wiki/Readers–writers_problem).
# Installation
Install the python package [readerwriterlock](https://pypi.python.org/pypi/readerwriterlock)
```bash
python3 -m pip install -U readerwriterlock
```
# Usage
1. Choose a rwlock class base on your access priority need and feature need which is going to be use by the threads:
| Priority | +Speed | +Downgradable* |
|---------------------------------------------------------------|-----------------|---------------|
| **Reader priority** (*aka First readers-writers problem*) | RWLockRead | RWLockReadD |
| **Writer priority** (*aka Second readers-writers problem*) | RWLockWrite | RWLockWriteD |
| **Fair priority** (*aka Third readers-writers problem*) | RWLockFair | RWLockFairD |
* **Downgradable** feature allows the locks to be atomically downgraded from being locked in write-mode to locked in read-mode
ⓘ Downgradable classes come with a theoretical ~20% negative effect on performance for acquiring and releasing locks.
2. Instantiate an instance of the chosen RWLock class:
```python
from readerwriterlock import rwlock
a = rwlock.RWLockFairD()
```
3. Generate read locks and write locks using the following methods:
```python
a_reader_lock = a.gen_rlock()
a_writer_lock = a.gen_wlock()
```
4. Use the generated read/write locks to protect section in your code:
## Pythonic usage example
```python
with a.gen_rlock():
#Read stuff
with a.gen_wlock():
#Write stuff
```
## Use case (Timeout) example
```python
b = a.gen_wlock()
if b.acquire(blocking=True, timeout=5):
try:
#Do stuff
finally:
b.release()
```
## Use case (Downgrade) example
```python
b = a.gen_wlock()
if b.acquire():
try:
#Read/Write stuff
b = b.downgrade()
#Read stuff
finally:
b.release()
```
## Live example
Refer to the file [test_rwlock.py](tests/test_rwlock.py) which has above 90% line coverage of [rwlock.py](readerwriterlock/rwlock.py).
The tests can be initiated by doing
```bash
make check.test.coverage
```
Contact
----
* Project: [GitHub](https://github.com/elarivie/pyReaderWriterLock)
* Éric Larivière <ericlariviere@hotmail.com>
[python]: https://www.python.org
[pyReaderWriterLock_repo]: https://github.com/elarivie/pyReaderWriterLock
[pyReaderWriterLock_BugTracker]: https://github.com/elarivie/pyReaderWriterLock/issues
[pyReaderWriterLock_repo_star]: https://github.com/elarivie/pyReaderWriterLock/stargazers
[pyReaderWriterLock_Pypi]: https://pypi.python.org/pypi/readerwriterlock
[pyReaderWriterLock_License]: https://github.com/elarivie/pyReaderWriterLock/blob/master/LICENSE.txt
Raw data
{
"_id": null,
"home_page": "https://github.com/elarivie/pyReaderWriterLock",
"name": "readerwriterlock",
"maintainer": "\u00c9ric Larivi\u00e8re",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "rwlock,read-write lock,lock,priority,reader,writer,fair,read,write,thread,synchronize",
"author": "\u00c9ric Larivi\u00e8re",
"author_email": "ericlariviere@hotmail.com",
"download_url": "https://files.pythonhosted.org/packages/a4/b9/6b7c390440ec23bf5fdf33e76d6c3b697a788b983c11cb2739d6541835d6/readerwriterlock-1.0.9.tar.gz",
"platform": "",
"description": "Reader Writer Lock\n==================\n\n**A python implementation of a solution for the three Reader-Writer problems.**\n\n[![repo status Active](https://www.repostatus.org/badges/latest/active.svg \"repo status Active\")](https://www.repostatus.org/#active)\n[![Build Status](https://travis-ci.org/elarivie/pyReaderWriterLock.svg?branch=master)](https://travis-ci.org/elarivie/pyReaderWriterLock)\n[![Coverage Status](https://codecov.io/gh/elarivie/pyreaderwriterlock/branch/master/graph/badge.svg)](https://codecov.io/gh/elarivie/pyreaderwriterlock)\n[![BugTracker](https://img.shields.io/github/issues/elarivie/pyReaderWriterLock.svg)][pyReaderWriterLock_BugTracker]\n\n\n[![Python Version](https://img.shields.io/pypi/pyversions/readerwriterlock.svg)][python]\n[![Pypi Version](https://img.shields.io/pypi/v/readerwriterlock.svg)][pyReaderWriterLock_Pypi]\n\n[![Code size in bytes](https://img.shields.io/github/languages/code-size/elarivie/pyReaderWriterLock.svg)][pyReaderWriterLock_repo]\n[![License](https://img.shields.io/pypi/l/readerwriterlock.svg)][pyReaderWriterLock_License]\n\n[![Downloads](https://pepy.tech/badge/readerwriterlock)](https://pepy.tech/project/readerwriterlock)\n[![Downloads](https://pepy.tech/badge/readerwriterlock/month)](https://pepy.tech/project/readerwriterlock/month)\n[![Downloads](https://pepy.tech/badge/readerwriterlock/week)](https://pepy.tech/project/readerwriterlock/week)\n[![pyReaderWriterLock_repo_star](https://img.shields.io/github/stars/elarivie/pyReaderWriterLock.svg?style=social&label=Stars)][pyReaderWriterLock_repo_star]\n\nNot only does it implement the reader-writer problems, it is also compliant with the python [lock interface](https://docs.python.org/3/library/threading.html#threading.Lock) which among others include support for timeout.\n\nFor reading about the theory behind the reader-writer problems refer to [Wikipedia](https://wikipedia.org/wiki/Readers\u2013writers_problem).\n\n# Installation\n\nInstall the python package [readerwriterlock](https://pypi.python.org/pypi/readerwriterlock)\n\n```bash\npython3 -m pip install -U readerwriterlock\n```\n\n# Usage\n\n1. Choose a rwlock class base on your access priority need and feature need which is going to be use by the threads:\n\n| Priority | +Speed | +Downgradable* |\n|---------------------------------------------------------------|-----------------|---------------|\n| **Reader priority** (*aka First readers-writers problem*) | RWLockRead | RWLockReadD |\n| **Writer priority** (*aka Second readers-writers problem*) | RWLockWrite | RWLockWriteD |\n| **Fair priority** (*aka Third readers-writers problem*) | RWLockFair | RWLockFairD |\n\n* **Downgradable** feature allows the locks to be atomically downgraded from being locked in write-mode to locked in read-mode\n\n\u24d8 Downgradable classes come with a theoretical ~20% negative effect on performance for acquiring and releasing locks.\n\n2. Instantiate an instance of the chosen RWLock class:\n\n```python\nfrom readerwriterlock import rwlock\na = rwlock.RWLockFairD()\n```\n3. Generate read locks and write locks using the following methods:\n\n```python\n a_reader_lock = a.gen_rlock()\n\n a_writer_lock = a.gen_wlock()\n```\n\n4. Use the generated read/write locks to protect section in your code:\n\n## Pythonic usage example\n\n```python\nwith a.gen_rlock():\n #Read stuff\n\nwith a.gen_wlock():\n #Write stuff\n```\n\n## Use case (Timeout) example\n```python\nb = a.gen_wlock()\nif b.acquire(blocking=True, timeout=5):\n try:\n #Do stuff\n finally:\n b.release()\n```\n\n## Use case (Downgrade) example\n\n```python\nb = a.gen_wlock()\nif b.acquire():\n try:\n #Read/Write stuff\n b = b.downgrade()\n #Read stuff\n finally:\n b.release()\n```\n\n## Live example\nRefer to the file [test_rwlock.py](tests/test_rwlock.py) which has above 90% line coverage of [rwlock.py](readerwriterlock/rwlock.py).\n\nThe tests can be initiated by doing\n\n```bash\nmake check.test.coverage\n```\n\nContact\n----\n* Project: [GitHub](https://github.com/elarivie/pyReaderWriterLock)\n* \u00c9ric Larivi\u00e8re <ericlariviere@hotmail.com>\n\n\n[python]: https://www.python.org\n[pyReaderWriterLock_repo]: https://github.com/elarivie/pyReaderWriterLock\n[pyReaderWriterLock_BugTracker]: https://github.com/elarivie/pyReaderWriterLock/issues\n[pyReaderWriterLock_repo_star]: https://github.com/elarivie/pyReaderWriterLock/stargazers\n[pyReaderWriterLock_Pypi]: https://pypi.python.org/pypi/readerwriterlock\n[pyReaderWriterLock_License]: https://github.com/elarivie/pyReaderWriterLock/blob/master/LICENSE.txt\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A python implementation of the three Reader-Writer problems.",
"version": "1.0.9",
"project_urls": {
"Download": "https://github.com/elarivie/pyReaderWriterLock",
"Homepage": "https://github.com/elarivie/pyReaderWriterLock",
"Source": "https://github.com/elarivie/pyReaderWriterLock",
"Tracker": "https://github.com/elarivie/pyReaderWriterLock/issues"
},
"split_keywords": [
"rwlock",
"read-write lock",
"lock",
"priority",
"reader",
"writer",
"fair",
"read",
"write",
"thread",
"synchronize"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c25a2f2e7fc026d5e64b5408aa3fbe0296a6407b8481196cae4daacacb3a3ae0",
"md5": "28d873dc6351b29a2ca9ce1e020adffa",
"sha256": "8c4b704e60d15991462081a27ef46762fea49b478aa4426644f2146754759ca7"
},
"downloads": -1,
"filename": "readerwriterlock-1.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "28d873dc6351b29a2ca9ce1e020adffa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 9999,
"upload_time": "2021-09-06T03:41:19",
"upload_time_iso_8601": "2021-09-06T03:41:19.435038Z",
"url": "https://files.pythonhosted.org/packages/c2/5a/2f2e7fc026d5e64b5408aa3fbe0296a6407b8481196cae4daacacb3a3ae0/readerwriterlock-1.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a4b96b7c390440ec23bf5fdf33e76d6c3b697a788b983c11cb2739d6541835d6",
"md5": "8ab86382fba7da8b7c88a1b5e7cec8e6",
"sha256": "b7c4cc003435d7a8ff15b312b0a62a88d9800ba6164af88991f87f8b748f9bea"
},
"downloads": -1,
"filename": "readerwriterlock-1.0.9.tar.gz",
"has_sig": false,
"md5_digest": "8ab86382fba7da8b7c88a1b5e7cec8e6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 16595,
"upload_time": "2021-09-06T03:41:21",
"upload_time_iso_8601": "2021-09-06T03:41:21.750723Z",
"url": "https://files.pythonhosted.org/packages/a4/b9/6b7c390440ec23bf5fdf33e76d6c3b697a788b983c11cb2739d6541835d6/readerwriterlock-1.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-09-06 03:41:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "elarivie",
"github_project": "pyReaderWriterLock",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "flake8",
"specs": []
},
{
"name": "mypy",
"specs": []
},
{
"name": "pydocstyle",
"specs": []
},
{
"name": "pylint",
"specs": []
},
{
"name": "setuptools",
"specs": []
},
{
"name": "twine",
"specs": []
},
{
"name": "typing_extensions",
"specs": []
},
{
"name": "wheel",
"specs": []
}
],
"lcname": "readerwriterlock"
}