Django-locking
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.
Metadata
Release files for django-db-locking 2.0.4
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 |
|---|---|---|---|---|
| django-db-locking-2.0.4.tar.gz | 9.7 kB | Without provenance | Details for django-db-locking-2.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_db_locking-2.0.4-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for django_db_locking-2.0.4-py2.py3-none-any.whl |
Total release size: 28.1 kB
Release files / django-db-locking-2.0.4.tar.gz
| Download URL | django-db-locking-2.0.4.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e328ca3bc8ea79e42a7c235775c85de82f65a2ac8a16bc81190799369e4fd92f
|
|
BLAKE2b-256 checksum How to use checksums |
32ff96980fd817f939575c60a9cfed3f24931e1632005e204a2f488c96f940aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_db_locking-2.0.4-py2.py3-none-any.whl
| Download URL | django_db_locking-2.0.4-py2.py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
7d6759624c368c634fa2e345b620911765ee606ea2bce8528db66a995165add9
|
|
BLAKE2b-256 checksum How to use checksums |
81d2a3550e9fa07aae3741a96f9fb844dadc72f6d551bddb8bedce913a3110e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-db-locking 2.0.4
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.