module documentation

Asynchronous file lock using portalocker.

This module provides a small async-compatible file lock wrapper around portalocker. It exposes Lock which can be used with async with to acquire a file-based lock without blocking the event loop (the implementation performs polling with asyncio.sleep).

The lock supports exclusive and shared modes and a configurable timeout/polling interval.

Examples

Acquire an exclusive lock:

async with Lock("/var/lock/my.lock"):
    # protected critical section
    do_stuff()

Acquire a shared lock with a short timeout:

async with Lock("/var/lock/my.lock", shared=True, timeout=0.5):
    read_shared_resource()
Class Lock Asynchronous context manager performing a file lock.