This package provides decorators that will try to acquire lock before calling decorated function.
Installation
pip install lockorator
Usage
This package provides two flavours of lock decorators: redis and asyncio. Both flavours have the same api.
Package lockorator.asyncio provides asyncio lock decorators, also compatible with trio.
Package lockorator.redis provides redis lock decorators.
To use redis locks, set LOCKORATOR_REDIS_URL in your environment:
export LOCKORATOR_REDIS_URL="redis://localhost:6379"
API
lock_or_exit
Decorator. Before decorated function starts, try to acquire lock with specified identifier. If lock is acquired successfully, proceed executing the function. Otherwise, return immediately. The id argument can contain templated string, wich will be rendered with args and kwargs, passed to the function.
Example:
from lockorator.asyncio import lock_or_exit
@lock_or_exit('lock_work_{}')
def workwork(x):
pass
workwork(3) # Will try to acquire lock 'lock_work_3'
lock_wait
Decorator. Before decorated function starts, try to acquire lock with specified identifier, waiting for waittime seconds if needed. If lock is acquired successfully, proceed executing the function. Otherwise, raise lockorator.TimeoutError. The id argument can contain templated string, wich will be rendered with args and kwargs, passed to the function.
Example:
from lockorator.redis import lock_wait
@lock_wait('lock_work_{}', waittime=4)
def workwork(x):
pass
workwork(3) # Will try to acquire lock 'lock_work_3' for 4 seconds
Metadata
Release files for lockorator 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lockorator-0.1.tar.gz | 3.0 kB | Without provenance | Details for lockorator-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lockorator-0.1-py3-none-any.whl | Python 3 | none | any | Details for lockorator-0.1-py3-none-any.whl |
Total release size: 7.9 kB
Release files / lockorator-0.1.tar.gz
| Download URL | lockorator-0.1.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c5beda474335f8f892ca1b775cc9e421668e2e9eb512ab65d25c8f586a35b9c2
|
|
BLAKE2b-256 checksum How to use checksums |
2e82f75e59aa950b5344e9d7710e90287755862700d94180ab6faea6d05db5b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Release files / lockorator-0.1-py3-none-any.whl
| Download URL | lockorator-0.1-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a6c29f15957e3d6225d732fda807f2818476e99f7821e2776128e0d15a8c235
|
|
BLAKE2b-256 checksum How to use checksums |
16f4e00961a2ffc6a9c9f663b5a6b29f51caeb91477ab5bdc4a8adcbb8a644e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Security for lockorator 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.