Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rwmutex-1.1.tar.gz (2.3 kB view hashes)

Uploaded Source

Built Distribution

rwmutex-1.1-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page