Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benjetson/py-rwmutex
Provides a threading read/write mutex lock usable with context managers.
https://github.com/benjetson/py-rwmutex
mutex python python3 threading threading-synchronization
Last synced: 10 days ago
JSON representation
Provides a threading read/write mutex lock usable with context managers.
- Host: GitHub
- URL: https://github.com/benjetson/py-rwmutex
- Owner: BenJetson
- License: mit
- Created: 2021-01-05T02:07:12.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-05T03:57:17.000Z (almost 4 years ago)
- Last Synced: 2024-12-06T02:07:59.885Z (28 days ago)
- Topics: mutex, python, python3, threading, threading-synchronization
- Language: Python
- Homepage: https://www.bengodfrey.net/py-rwmutex/
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# py-rwmutex
This package provides a simple read/write mutex lock for threads, based upon
the `threading` package. It supports Python's context manager interface, so
it may be used within `with` statements.## Purpose
This read/write lock can improve performance by allowing multiple threads to
reaad from a shared resource at once. For safety, only one thread is granted
a write lock at a time, and only when no threads have a read lock.## Installation
This package is available from [PyPi](https://pypi.org/project/rwmutex/), which
means it can be easily acquired via [`pip`](https://pypi.org/project/pip/).Run this command at a shell prompt:
```bash
pip3 install rwmutex
```## Usage
To get started, import the package like so:
```py
from rwmutex import RWLock
```Then you can declare a lock object:
```py
lock = RWLock()
```To use the lock, you can use `with` blocks:
```py
with lock.write
# some operation that writes
passwith lock.read:
# some operation that just needs to read
pass
```For a working example, see [example.py](example.py).