Provides a read/write mutex lock usable with context managers.
Project description
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, which
means it can be easily acquired via pip
.
Run this command at a shell prompt:
pip3 install rwmutex
Usage
To get started, import the package like so:
from rwmutex import RWLock
Then you can declare a lock object:
lock = RWLock()
To use the lock, you can use with
blocks:
with lock.write
# some operation that writes
pass
with lock.read:
# some operation that just needs to read
pass
For a working example, see example.py.
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
File details
Details for the file rwmutex-1.1.tar.gz
.
File metadata
- Download URL: rwmutex-1.1.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8fdc87810aa6b0b7b4c02c1612cc66141e91bd45bad8556e3305cdc2123d393 |
|
MD5 | 55d8646116a685063c434fb5a6b867ea |
|
BLAKE2b-256 | 7bd7bbbdf48e9f55189533337adfcfa9fa3211a9dab9a1122dca5f0dc22ccc5d |
File details
Details for the file rwmutex-1.1-py3-none-any.whl
.
File metadata
- Download URL: rwmutex-1.1-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69a8256ccbd0e061fc8c14892d8d2b3b64d8d8c7b8e6f1abbd607c5147cfb6c7 |
|
MD5 | 53975b66999086cca9e6d7cabadd0642 |
|
BLAKE2b-256 | 139ba1105cb2e6a67d9019563c3240da6a2111112a092799c31ce0017d527f70 |