Database locking
Project description
Usage
The simplest use is by using it as a context manager:
with NonBlockingLock.objects.acquire_lock(obj=model_obj): model_obj.do_something()
Or you can keep track of the lock yourself:
try: lock = NonBlockingLock.objects.acquire_lock(obj=model_obj) except AlreadyLocked: return False model_obj.do_something() lock.release()
If you have no Django model, or you want to be able to specify the lock name yourself, you can do that too:
# this will raise AlreadyLocked, if it's locked lock = NonBlockingLock.objects.acquire_lock(lock_name='my_lock') do_something() lock.release()
Test
You can run the tests with
tox
Wishlist
Add lock time-out (try to aquire a lock for up to a given TIME_OUT), like lockfile’s FileLock.aquire
Global locks (for instance on a whole Model not just an object)
Releases
- v1.2.0:
Move id to UUIDField, add code quality checks and CI
- v1.1.0:
Rename model to NonBlockingLock and add additional features
- v1.0.1:
Corrected tests and code clean-up
- v1.0.0:
Intial release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Close
Hashes for django-db-locking-1.2.0.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b12dfba386a09460212a6782381d4dcf7fe32f7675c60304400a3124a63a84c |
|
MD5 | f2030d57ed35d3837534340c165a1387 |
|
BLAKE2b-256 | acb116809e3066ddc0a5823161175007f70183356386f4a35378d1c5317f31b9 |