Registry / http-networking / aiorwlock

aiorwlock

JSON →
library1.5.1pypypi✓ verified 24d ago

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 aiorwlock
INSTALL
IMPORT
SIG · AIORWLOCK
A
aiorwlock
http-networkingpythonv1.5.1
Install
1.6s avg
Import
202ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.214s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.190s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RWLock
from aiorwlock import RWLock

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.

import asyncio from aiorwlock import RWLock async def reader_task(rwlock: RWLock, reader_id: int): print(f"Reader {reader_id}: Attempting to acquire read lock") async with rwlock.reader_lock: print(f"Reader {reader_id}: Acquired read lock") await asyncio.sleep(0.05) # Simulate reading print(f"Reader {reader_id}: Released read lock") async def writer_task(rwlock: RWLock, writer_id: int): print(f"Writer {writer_id}: Attempting to acquire write lock") async with rwlock.writer_lock: print(f"Writer {writer_id}: Acquired write lock") await asyncio.sleep(0.1) # Simulate writing print(f"Writer {writer_id}: Released write lock") async def main(): rwlock = RWLock() tasks = [] # Start some readers for i in range(3): tasks.append(asyncio.create_task(reader_task(rwlock, i))) # Start a writer in between tasks.append(asyncio.create_task(writer_task(rwlock, 100))) # Start more readers for i in range(3, 6): tasks.append(asyncio.create_task(reader_task(rwlock, i))) await asyncio.gather(*tasks) if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingPython 3.7 support was dropped in v1.4.0. Users on Python 3.7 or older must upgrade their Python version to use `aiorwlock` v1.4.0 or newer.
fix
Upgrade Python to 3.8 or newer. The current minimum supported version is Python 3.9.
affects: >=1.4.0
breakingThe explicit `loop` parameter for the `RWLock` constructor was deprecated in v1.0.0 and removed in v1.3.0. Passing a `loop` argument will now raise an error.
fix
Remove the `loop` argument from `RWLock()` constructor calls. `aiorwlock` now lazily evaluates the current event loop.
affects: >=1.3.0
deprecatedCreation of `RWLock` instances outside of an `async` function context was deprecated in v1.0.0. While it might still work in some setups due to lazy loop evaluation, it's considered bad practice.
fix
Ensure `RWLock()` instances are created within an `async` function or a context where `asyncio.get_running_loop()` can correctly resolve the event loop.
affects: >=1.0.0
gotchaFixed a cross-event-loop race condition in lock acquisition and a deadlock that could occur when tasks are cancelled.
fix
Upgrade to `aiorwlock` v1.5.1 or newer to benefit from critical stability fixes.
affects: <1.5.1
gotchaFixed a bug that allowed concurrent writes under rare conditions.
fix
Upgrade to `aiorwlock` v1.2.0 or newer to ensure correct exclusive write lock behavior.
affects: <1.2.0
gotchaA `RuntimeError` will be raised if a lock is acquired by one task but released by another. Synchronization primitives in `asyncio` are typically task-bound.
fix
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`).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'aiorwlock'
The 'aiorwlock' module is not installed in the Python environment.
fix
pip install aiorwlock
AttributeError: module 'aiorwlock' has no attribute 'RWLock'
The 'RWLock' class is not found in the 'aiorwlock' module, possibly due to an incorrect import statement.
fix
from aiorwlock import RWLock
RuntimeError: Task got Future <Future pending> attached to a different loop
An attempt was made to use 'aiorwlock' across different asyncio event loops, which is not supported.
fix
Ensure that the 'RWLock' instance is used within the same asyncio event loop where it was created.
RuntimeError: A task that acquires the lock should be used for releasing it.
The read-write lock was acquired by one asyncio task but attempted to be released by a different task, which is not permitted by `aiorwlock`'s design.
fix
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.
RuntimeWarning: coroutine 'RWLock.reader_lock' was never awaited
You are calling an asynchronous method or accessing an awaitable context manager (like `rwlock.reader_lock` or `rwlock.writer_lock`) but are not using the `await` keyword or `async with` statement to schedule or enter it.
fix
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()`.
Upgrade
Version history
1.5.1latest on PyPI · released Feb 20, 2026
Audit
Dependencies
pythonrequiredRequired runtime environment.
Agent activity
67 hits · last 30 days
node
54
OpenAI (training)
1
Resources
aiorwlock — pip install aiorwlock · libregistry