Skip to main content

Process-shared Reader-Writer locks for Python

https://travis-ci.org/trovao/prwlock.svg https://coveralls.io/repos/trovao/prwlock/badge.svg?branch=master&service=github

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.

Usage

There is no need for initialization. Therefore, a code block such as the one below is enough to get an RWLock instance.

from prwlock.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.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])

Metadata

Release files for prwlock 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prwlock 0.1.0
File Size Uploaded
prwlock-0.1.0.tar.gz 5.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for prwlock 0.1.0
File Interpreter ABI Platform
prwlock-0.1.0-py3-none-any.whl Python 3 none any Details
prwlock-0.1.0-py2-none-any.whl Python 2 none any Details

Total release size: 19.6 kB

Release files / prwlock-0.1.0.tar.gz

Download URL prwlock-0.1.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
332c1481ad1b4035a4679c6e998e91c5f5db7864bc297575cc3a02f086ce342b
BLAKE2b-256 checksum
How to use checksums
e65c80ce26e81eadaf7a66adc636d46bd01cfa65f7969967d88eb40efaa09372
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / prwlock-0.1.0-py3-none-any.whl

Download URL prwlock-0.1.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
192130cc66674d9a08a18ecf9ea6de9748ca707b876d130c60d89b6b7fb4e86c
BLAKE2b-256 checksum
How to use checksums
dd6ced53897db1d196b5189837ad9a34549ba934b3b5f79f0339e1a70683bdba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / prwlock-0.1.0-py2-none-any.whl

Download URL prwlock-0.1.0-py2-none-any.whl
Size 7.2 kB
Tags Python 2
SHA-256 checksum
How to use checksums
c745be90fb73ba3b80209f33b587759a19bdd1bef1915db5c52bef8beb30a0b9
BLAKE2b-256 checksum
How to use checksums
27086a5d845e31563b4f3ae4986a71b3f2633c670e6d3d84533388c7fdacfa35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.4.1

2 release files

0.4.0

3 release files

0.3.0

3 release files

0.2.0

3 release files

0.1.1

3 release files

This release

0.1.0 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page