This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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

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.
Release History

Release History

This version
History Node

2.0.1

History Node

2.0.0

History Node

1.2.1

History Node

1.2.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django_db_locking-2.0.1-py2.py3-none-any.whl (15.6 kB) Copy SHA256 Checksum SHA256 3.6 Wheel Jun 8, 2017
django-db-locking-2.0.1.tar.gz (9.0 kB) Copy SHA256 Checksum SHA256 Source Jun 8, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting