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()
Note that locks can expire automatically. There is a LOCK_MAX_AGE settings where you can specify a default lock release value for locks in your entire Django codebase. This value can be overridden per lock by setting the max_age parameter.
Test
You can run the tests with
tox
Releases
- v2.0.0:
Merging of master and pre-django-1.8 branches Removes management command in favor of a celery task
- v1.2.1:
Fix problem in migration to UUIDField for PostGres
- 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 Distribution
Built Distribution
File details
Details for the file django-db-locking-2.0.4.tar.gz
.
File metadata
- Download URL: django-db-locking-2.0.4.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e328ca3bc8ea79e42a7c235775c85de82f65a2ac8a16bc81190799369e4fd92f |
|
MD5 | cd04f079fda7ddd19b953b25e4e2d2be |
|
BLAKE2b-256 | 32ff96980fd817f939575c60a9cfed3f24931e1632005e204a2f488c96f940aa |
File details
Details for the file django_db_locking-2.0.4-py2.py3-none-any.whl
.
File metadata
- Download URL: django_db_locking-2.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d6759624c368c634fa2e345b620911765ee606ea2bce8528db66a995165add9 |
|
MD5 | 33d22e08c637a5293a052251a2142465 |
|
BLAKE2b-256 | 81d2a3550e9fa07aae3741a96f9fb844dadc72f6d551bddb8bedce913a3110e5 |