Distributed locks for Django using Zookeeper.
Project description
Distributed locks for Django using Zookeeper
Installation
pip install django-zk-locks
Usage
django-zk-locks exposes one single the lock contextmanager and the locked decorator.
The locked decorator will wrap a django management command (subclasses of django.core.management.base.BaseCommand) or any function with the lock contextmanager:
from django.core.management.base import BaseCommand
from database_locks import locked
@locked
class Command(BaseCommand):
...
def handle(self, *args, **options):
self.stdout.write('Got the lock')
from database_locks import locked
class SomeClass:
def non_locked(self):
pass
@locked
def locked(self):
print('got lock')
from database_locks import lock
class SomeClass:
def non_locked(self):
pass
def locked(self):
with lock():
print('got lock')
Docs
Both lock and locked have the same optional args:
:param lock_name: unique name in DB for this function
There are also the following options you can specify in the project settings.py
ZOOKEEPER_LOCKS_STATUS_FILE: file that will be updated with the lock status (default None). Useful when you have multiple shared-lock processes, to quickly inspect which one has the lock.
ZOOKEEPER_LOCKS_ENABLED: set to False to globally disable locks (default True)
ZOOKEEPER_LOCKS_HOSTS: connection string for Zookeeper, such as “localhost:2181,localhost:2182,localhost:2183”
Testing
Tox is used by the Github Action to test several python and django versions.
To quickly test locally, kick off a Zookeeper docker container:
- docker run -d –name locks-test
-p 2181:2181 zookeeper:3.9
List available environments with tox -l and then run the one you want/have:
tox -e py310-dj42
Project details
Release history Release notifications | RSS feed
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_zk_locks-0.0.1.tar.gz
.
File metadata
- Download URL: django_zk_locks-0.0.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7d9ce9fa2adae190f6edc68f2963e12079c8eb8756d69910e074f24963938a6 |
|
MD5 | d5330819f3e16221329a17ba52e8c030 |
|
BLAKE2b-256 | 8976def2aeb4eaa6b48b61ca7a25afc95e7838ae234e83cd4bdb3c63122d239c |
File details
Details for the file django_zk_locks-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_zk_locks-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8f3b2a6d08bcdeea1c43dab012eccf9f9c3641e66a079e87003ab06972d2aab |
|
MD5 | c3a2a938531fb673e4056de7a7d1bae9 |
|
BLAKE2b-256 | 0edc95322a4efb8311f21416d436d2af2bb92cb9af97acfd5811f264fc95d670 |