module documentation

Asynchronous file lock using portalocker.

This module wraps portalocker for asynchronous use. Use Lock with async with to get a file lock without blocking the event loop. The implementation polls 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.