This package provides a simple read/write mutex lock for threads, based upon
threading package. It supports Python’s context manager interface, so
it may be used within
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.
Run this command at a shell prompt:
pip3 install rwmutex
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 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.