Skip to content
Use the Django ORM to lock objects in the database
Python
Find file
Pull request Compare This branch is 48 commits behind vikingco:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
locking
.gitignore
README.rst
setup.py

README.rst

Django-locking

Usage

If you want to lock a Django model, you can pass it along.

try:
    lock = Lock.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 to:

# this will raise AlreadyLocked, if it's locked
lock = Lock.objects.acquire_lock(lock_name='my_lock')
do_something()
lock.release()

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.0.1:
Corrected tests and code clean-up
v1.0.0:
Intial release.
Something went wrong with that request. Please try again.