Skip to content

Provides a threading read/write mutex lock usable with context managers.

License

Notifications You must be signed in to change notification settings

BenJetson/py-rwmutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.