skip to navigation
skip to content

prwlock 0.2.0

Native process-shared rwlock support for Python

Latest Version: 0.4.0

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.


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

$ pip install prwlock


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')
        print(os.getpid(), 'Sleeping for a while')
        print(os.getpid(), 'Releasing lock')

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


  • 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
File Type Py Version Uploaded on Size
prwlock-0.2.0-py2-none-any.whl (md5) Python Wheel py2 2016-01-08 11KB
prwlock-0.2.0-py3-none-any.whl (md5) Python Wheel py3 2016-01-08 11KB
prwlock-0.2.0.tar.gz (md5) Source 2016-01-08 7KB