Skip to main content

Privex's Django Database Lock Manager

Build Status Codecov PyPi Version License Button PyPI - Downloads PyPI - Python Version PyPI - Django Version GitHub last commit

+===================================================+
|                 © 2019 Privex Inc.                |
|               https://www.privex.io               |
+===================================================+
|                                                   |
|        Django Database Lock Manager               |
|        License: X11/MIT                           |
|                                                   |
|        Core Developer(s):                         |
|                                                   |
|          (+)  Chris (@someguy123) [Privex]        |
|                                                   |
+===================================================+

Django Database Lock Manager - Easy to use lock system using your Django app's database
Copyright (c) 2019    Privex Inc. ( https://www.privex.io )

Install with pip

We recommend at least Python 3.6 - we cannot guarantee compatibility with older versions.

pip3 install django-lockmgr

Add lockmgr to your INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin.apps.SimpleAdminConfig',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    # ...
    'lockmgr'
]   

Run the migrations

./manage.py migrate lockmgr

Usage

Use the LockMgr in your code like so:

from lockmgr.lockmgr import LockMgr, Locked

try:
    with LockMgr('mylock') as lck:
        print('The lock "mylock" is now locked.')
        lck.lock('otherlock')
        print('The lock "otherlock" should also be locked.')
    print('The locks "mylock" and "otherlock" should now both be cleared.')
except Locked as e:
    print('Error! mylock is already locked: ', type(e), str(e))

If you want to wait for the lock to be released, rather than immediately excepting:

from lockmgr.lockmgr import LockMgr, Locked

try:
    # expires=60 means the lock will expire after 60 seconds if you don't renew it.
    # wait=90 (must be in 5 second intervals) means: if the key is locked, retry every 5 seconds, if 90 seconds have 
    #         passed and it's still locked, then give up and raise Locked.
    with LockMgr('somelock', expires=60, wait=90) as lck:
        print('The lock "somelock" is now locked.')
    print('The lock "somelock" should now be cleared.')
except Locked as e:
    print('Error! After retrying for 90 seconds, "somelock" is still locked: ', type(e), str(e))

Unit Tests

To run the unit tests, clone the project and make a .env file containing details for a database:

DB_BACKEND=mysql
DB_NAME=lockmgr
DB_USER=someuser
DB_PASS=mypassword

Install all required dependencies:

pip3 install -r requirements.txt -U

Now run the tests (--verbose for more detailed testing output):

./manage.py test --verbose

Metadata

Release files for django-lockmgr 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-lockmgr 2.0.0
File Size Uploaded Provenance
django-lockmgr-2.0.0.tar.gz 20.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-lockmgr 2.0.0
File Interpreter ABI Platform
django_lockmgr-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.5 kB

Release files / django-lockmgr-2.0.0.tar.gz

Download URL django-lockmgr-2.0.0.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
38034cc1fcd779ff09e394198456c2b18bfa075195d93c22125acf0840797640
BLAKE2b-256 checksum
How to use checksums
83c286e4619a3d680dcfaa3cb1ee0d9c672cbce80c46f069ebd8c70bdc6517ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

Release files / django_lockmgr-2.0.0-py3-none-any.whl

Download URL django_lockmgr-2.0.0-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6836af3156c024787bbd651eea7fe82a655cf61123f9f9904d1980007a7430a1
BLAKE2b-256 checksum
How to use checksums
e558a9c5fe33a7269bb150e9b511ce755aaebacba5f9bec675306a2b3d8ce5ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

Security for django-lockmgr 2.0.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page