Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Wool Locking

Wool Locking is an extension of the Wool framework, providing distributed locking primitives for inter-worker and inter-pool synchronization. It allows for the execution of tasks within a locking session, ensuring safe and efficient coordination in distributed environments.

Installation

Using pip

To install the package using pip, run the following command:

[uv] pip install --pre wool-locking

Cloning from GitHub

To install the package by cloning from GitHub, run the following commands:

git clone https://github.com/wool-labs/wool.git
cd wool/wool-locking
[uv] pip install .

Usage

Locking Decorator

The @wool.locking.lock decorator allows you to execute a function within a lock session. If no lock session is found in the current context, a local lock is used as a fallback.

import wool.locking

@wool.locking.lock
async def critical_section():
    # Code that requires distributed locking
    ...

Lock Pool

The wool.locking.pool function creates a specialized worker pool for managing distributed locking tasks. It uses a single worker and integrates with LockPoolSession and LockScheduler.

import wool.locking

@wool.locking.pool(port=48900, authkey=b"lockkey")
async def locked_task():
    # Code executed within the lock pool
    ...

Lock Pool Session

The wool.locking.session function declares a lock pool session context. This can be used to tightly couple tasks with a specific lock pool.

import wool.locking

@wool.locking.session(port=48900, authkey=b"lockkey")
@wool.task
async def locked_task():
    # Code executed within the lock pool session
    ...

Sample Application

Below is an example of how to use Wool Locking to execute tasks with distributed locking:

Module defining locked tasks: tasks.py

import asyncio, wool.locking

@wool.locking.lock
async def locked_task(x, y):
    await asyncio.sleep(1)
    return x + y

Module executing locked workflow: main.py

import asyncio, wool.locking
from tasks import locked_task

async def main():
    with wool.locking.session(port=48900, authkey=b"lockkey"):
        result = await locked_task(1, 2)
        print(f"Result: {result}")

asyncio.new_event_loop().run_until_complete(main())

To run the demo, first start a lock pool specifying the module defining the tasks to be executed:

wool lock-pool up --port 48900 --authkey deadbeef

Next, in a separate terminal, execute the application defined in main.py and, finally, stop the lock pool:

python main.py
wool lock-pool down --port 48900 --authkey deadbeef

License

This project is licensed under the Apache License Version 2.0.

Metadata

Release files for wool-locking 0.1rc9

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

Source distribution (sdist)

Source distribution for wool-locking 0.1rc9
File Size Uploaded
wool_locking-0.1rc9.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wool-locking 0.1rc9
File Interpreter ABI Platform
wool_locking-0.1rc9-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / wool_locking-0.1rc9.tar.gz

Download URL wool_locking-0.1rc9.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bebc6ebc999330c2a2b066537479834daca50666ea7388ceaf244066efbb2bc1
BLAKE2b-256 checksum
How to use checksums
456bbec656e8f783bc5b819b966e1307a9007a21a3d287bd7d0d439f6c13c85a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.0

Release files / wool_locking-0.1rc9-py3-none-any.whl

Download URL wool_locking-0.1rc9-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
821a9475ce74b027db6be6a6bd93fda92fab2afd922cea50c7cc04fd2a4f13fc
BLAKE2b-256 checksum
How to use checksums
405333f864e93ac5b2a4dfa17e0d648a852488ef9803d9ea49e58bc3d50d006e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.0
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