Reacquiring lock for redis
Project description
Lock that prolongs itself from time to time and cancels current task if used as async context manager.
Usage
import asyncio
import logging
from redis.asyncio import Redis
from redis_extending_lock import ExtendingLock
async def main():
redis = Redis.from_url('redis://:hackme@localhost:6379/0')
lock = ExtendingLock(
redis, 'example',
timeout=2,
# optional, if not specified explicitly
# would be half of timeout
reacquiring_timeout=1,
blocking_timeout=0,
)
async with lock:
# your long-running task,
# would be cancelled if lock would be not able to extend
# for some reason
await asyncio.Future()
logging.basicConfig(level=logging.DEBUG)
asyncio.run(main())
Lock can be also used without context manager:
import asyncio
import logging
from redis.asyncio import Redis
from redis_extending_lock import ExtendingLock
async def main():
redis = Redis.from_url('redis://:hackme@localhost:6379/0')
lock = ExtendingLock(
redis, 'example', timeout=2, blocking_timeout=0,
)
await lock.acquire()
await asyncio.sleep(5)
await lock.release()
logging.basicConfig(level=logging.DEBUG)
asyncio.run(main())
How to develop
make devenv - configure the development environment
poetry shell or source .venv/bin/activate - activate virtualenv
make lint - syntax & code style check
make codestyle - reformat code
make test - test this project
make build - build this project
Versioning
This software follows Semantic Versioning.
Version is represented using MAJOR.MINOR.PATCH numbers, increment the:
MAJOR version when you make incompatible API changes
MINOR version when you add functionality in a backwards compatible manner
PATCH version when you make backwards compatible bug fixes
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
In this case, the package version is assigned automatically with poem-plugins, it using on the tag in the repository as a major and minor and the counter, which takes the number of commits between tag to the head of branch.
Project details
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
File details
Details for the file redis_extending_lock-0.0.4.tar.gz
.
File metadata
- Download URL: redis_extending_lock-0.0.4.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.9.16 Linux/5.15.0-1034-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 401a3e66ee4e1f1a1c66bdc11eb5ed633c17e22abafcb0a3a3e1ead376cf18bb |
|
MD5 | 3292643fdc533b48d5bf205c0edf4700 |
|
BLAKE2b-256 | 1fb3624d0dc680c1c0f2be0c89588cf36a1236c71f3df431d18dfa792963325d |
File details
Details for the file redis_extending_lock-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: redis_extending_lock-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.9.16 Linux/5.15.0-1034-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e570c758428244919cef09fa0a7f6599e8df766cd7ef732f0f7a4a86e3a95680 |
|
MD5 | 39100435bd05f350a5d557659415fdeb |
|
BLAKE2b-256 | 43940c889a5b09f49dddcd92709d645c7efb9db81132a72b39934749ce0b6c10 |