proxywhirl.rwlock¶
Readers-writer locks for high-concurrency scenarios.
This module provides both async and sync RWLock implementations for allowing multiple concurrent readers but exclusive writer access.
Classes¶
Async readers-writer lock for high-concurrency scenarios. |
|
Synchronous readers-writer lock for high-concurrency scenarios. |
Module Contents¶
- class proxywhirl.rwlock.AsyncRWLock[source]¶
Async readers-writer lock for high-concurrency scenarios.
Allows multiple concurrent readers but exclusive writer access. Prevents read operations from blocking each other while maintaining data consistency for writes.
This is a thin wrapper around aiorwlock.RWLock providing a consistent interface with method-based context manager access.
Example
>>> rwlock = AsyncRWLock() >>> async with rwlock.read_lock(): ... # Multiple readers can acquire simultaneously ... value = shared_data.read() >>> async with rwlock.write_lock(): ... # Only one writer at a time ... shared_data.write(new_value)
Initialize the RWLock.
- class proxywhirl.rwlock.SyncRWLock[source]¶
Synchronous readers-writer lock for high-concurrency scenarios.
Allows multiple concurrent readers but exclusive writer access. Prevents read operations from blocking each other while maintaining data consistency for writes.
This is a thin wrapper around readerwriterlock.RWLockFair providing a consistent interface with the async version.
Features: - Multiple readers can hold the lock simultaneously - Writers get exclusive access (no readers or other writers) - Fair scheduling to prevent writer starvation
Example
>>> rwlock = SyncRWLock() >>> with rwlock.read_lock(): ... # Multiple readers can acquire simultaneously ... value = shared_data.read() >>> with rwlock.write_lock(): ... # Only one writer at a time ... shared_data.write(new_value)
Initialize the SyncRWLock.
- read_lock()[source]¶
Context manager for read locks.
Allows multiple concurrent readers.
Example
>>> with rwlock.read_lock(): ... # Multiple threads can read simultaneously ... data = shared_resource.read()
- Return type:
collections.abc.Iterator[None]
- write_lock()[source]¶
Context manager for write locks.
Provides exclusive access - no concurrent readers or writers.
Example
>>> with rwlock.write_lock(): ... # Exclusive access guaranteed ... shared_resource.write(new_data)
- Return type:
collections.abc.Iterator[None]