aiorwlock provides a read-write lock, a synchronization primitive for `asyncio` applications. It allows multiple reader tasks to hold a lock concurrently, while a writer task obtains an exclusive lock, blocking all readers and other writers. This pattern is ideal for resources that are frequently read but infrequently written. The library is currently at version 1.5.1 and maintains an active release cadence with several minor and patch updates per year.
pip install aiorwlockVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic usage of `RWLock` with multiple concurrent readers and a single writer. Readers can acquire the `reader_lock` simultaneously, but a writer acquiring the `writer_lock` will block all other readers and writers.
Upgrade Python to 3.8 or newer. The current minimum supported version is Python 3.9.
Remove the `loop` argument from `RWLock()` constructor calls. `aiorwlock` now lazily evaluates the current event loop.
Ensure `RWLock()` instances are created within an `async` function or a context where `asyncio.get_running_loop()` can correctly resolve the event loop.
Upgrade to `aiorwlock` v1.5.1 or newer to benefit from critical stability fixes.
Upgrade to `aiorwlock` v1.2.0 or newer to ensure correct exclusive write lock behavior.
Always ensure that the same `async` task (coroutine) that acquires a `reader_lock` or `writer_lock` is also responsible for releasing it (e.g., by using `async with`).
pip install aiorwlock
from aiorwlock import RWLock
Ensure that the 'RWLock' instance is used within the same asyncio event loop where it was created.
Ensure that the `RWLock`'s reader or writer lock is acquired and released within the same asyncio task, typically by using `async with` statements or by calling `acquire()` and `release()` from the same coroutine.
Prepend `await` when calling `acquire()` or use `async with` when entering the reader/writer lock context. For example, `async with rwlock.reader_lock:` or `await rwlock.reader_lock.acquire()`.