Named Locks to acquire lock by name
Project description
NamedLocks
NamedLocks is a simple library for locking on a name.
Installation
pip install namedlocks
Usage
import asyncio
from random import randint, uniform
from named_locks import AsyncNamedLock
NAMED_LOCKS = AsyncNamedLock() # Create a global instance of the lock
async def task(uid: int):
async with NAMED_LOCKS.lock(uid): # Lock on some name
print(f"Task {uid} started")
# do something
await asyncio.sleep(uniform(1, 5))
print(f"Task {uid} finished")
async def main():
tasks = [asyncio.create_task(task(uid)) for uid in [randint(1, 10) for _ in range(50)]]
await asyncio.gather(*tasks)
asyncio.run(main())
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
namedlocks-0.0.1a3.tar.gz
(2.7 kB
view details)
Built Distribution
File details
Details for the file namedlocks-0.0.1a3.tar.gz
.
File metadata
- Download URL: namedlocks-0.0.1a3.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d7492230e20ac359444fbad2625b7d6b6ba204fdcea3154d7a7962cd713d55d |
|
MD5 | fc641f379b328e084ce96ee5487d5c43 |
|
BLAKE2b-256 | ad6aed9d1f507ff167d1f9fda967e41e82922ac5c0161d2d3a23f698301f9da3 |
File details
Details for the file namedlocks-0.0.1a3-py3-none-any.whl
.
File metadata
- Download URL: namedlocks-0.0.1a3-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0654dd91da640211f226cbe1fbeb1fe5bfd66c3626666e730cbea6cb0b6c1366 |
|
MD5 | d13805731e726c4dff1c8ef62e0407fb |
|
BLAKE2b-256 | 4e3798397ffecd8974bd383f46b02d3032270417c98d9421608400c232641835 |