Read write lock for asyncio.
Project description
Read write lock for asyncio . A RWLock maintains a pair of associated locks, one for read-only operations and one for writing. The read lock may be held simultaneously by multiple reader tasks, so long as there are no writers. The write lock is exclusive.
Whether or not a read-write lock will improve performance over the use of a mutual exclusion lock depends on the frequency that the data is read compared to being modified. For example, a collection that is initially populated with data and thereafter infrequently modified, while being frequently searched is an ideal candidate for the use of a read-write lock. However, if updates become frequent then the data spends most of its time being exclusively locked and there is little, if any increase in concurrency.
Implementation almost direct port from this patch.
Example
import asyncio
import aiorwlock
loop = asyncio.get_event_loop()
@asyncio.coroutine
def go():
rwlock = aiorwlock.RWLock(loop=loop)
with (yield from rwlock.writer_lock):
# or same way you can acquire reader lock
# with (yield from rwlock.reader_lock): pass
print("inside writer_lock")
yield from asyncio.sleep(0.1, loop=loop)
loop.run_until_complete(go())
License
aiorwlock is offered under the Apache 2 license.
Changes
0.1.0 (2014-12-22)
Initial release;
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aiorwlock-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acb2dfa5b47b073d9a9befd67f7b64d573232cfbb9a7fa8460f695c2c264090b |
|
MD5 | 7d5a096669ec12d2ee91159bfae93137 |
|
BLAKE2b-256 | 1bfdd953454851fa6da2bf1931818602312a4251bf8277e31c668ee22a00ea49 |