This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A reader-writer lock for Python that can (must, actually) be used for locking across multiple Python processes.

The rationale and initial implementation of the project can be found in the accompanying blog post.

Installation

This package is available on PyPi, so you can install the latest stable release with a simple pip call:

$ pip install prwlock

Usage

All you have to do is import the module and start using it. There is no need for initialization. Therefore, a code block such as the one below is enough to get an RWLock instance.

from prwlock import RWLock

rwlock = RWLock()

The RWLock itself is pickleable and, therefore, can be passed around to child processes, such as in the code block below.

from __future__ import print_function

import os
import time

from multiprocessing import Pool
from prwlock import RWLock
def f(rwlock):
    for i in range(2):
        print(os.getpid(), 'Acquiring read lock')
        rwlock.acquire_read()
        print(os.getpid(), 'Sleeping for a while')
        time.sleep(1)
        print(os.getpid(), 'Releasing lock')
        rwlock.release()
        time.sleep(.1)

r = RWLock()
children = 20
pool = Pool(processes=children)
for child in range(children):
    pool.apply_async(f, [r])

Context Managers

prwlock also supports context managers using the with syntax. The code block below displays one possible way of using it.

from prwlock import RWLock

# First you instantiate the lock
rwlock = RWLock()

# Now you can lock it in read or in write mode
with rwlock.reader_lock():
    # If this executes, then reader lock access has been acquired
    print('Reading data')

# Likewise, you can lock in writer mode with:
with rwlock.writer_lock():
    print('Writing data')

Changes

  • 0.4.0: Added context-management support using the with syntax;

  • 0.3.0: Completed the API’s implementation. Namely:
    • Added support for immediate failure when locks cannot be obtained;
    • Added timeouts for obtaining the locks.
  • 0.2.0: Added support for RWLocks on Windows XP and above. Changed the API so that the lock can be imported as from prwlock import RWLock, instead of the slightly awkward from prwlock.prwlock import RWLock method.

  • 0.1.1: Fixed the value of the PTHREAD_PROCESS_SHARED constant for Mac OS X. Also added a check to prevent double destruction of the underlying lock on Mac OS X.

  • 0.1.0: Initial release

Release History

Release History

0.4.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
prwlock-0.4.0-py2-none-any.whl (15.5 kB) Copy SHA256 Checksum SHA256 py2 Wheel Oct 18, 2016
prwlock-0.4.0-py3-none-any.whl (15.5 kB) Copy SHA256 Checksum SHA256 py3 Wheel Oct 18, 2016
prwlock-0.4.0.tar.gz (10.4 kB) Copy SHA256 Checksum SHA256 Source Oct 18, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting