Skip to main content

A distributed lock implementation based on SQLAlchemy

Project description

SQLAlchemy-DLock

Documentation Status

Distributed lock based on Database and SQLAlchemy.

It currently supports locks of:

It's not stable and DO NOT use it in production.

Usages

Basic usage:

# ...
from sqlalchemy import create_engine
from sqlalchemy_dlock import sadlock

# ...

lock_key = 'user/001'

# ...

engine = create_engine('postgresql://scott:tiger@localhost/')

# ...

with engine.connect() as conn:
    with sadlock(conn, lock_key):
        pass
        # locked here!
        # ...
    pass
    # unlocked here!
    # ...
# ...

Work with SQLAlchemy's Session:

# ...
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_dlock import sadlock

# ...

lock_key = 'user/001'

# ...

engine = create_engine('postgresql://scott:tiger@localhost/')
Session = sessionmaker(bind=engine)

# ...

session = Session()

# ...

with session.bind.connect() as conn:
    with sadlock(conn, lock_key):
        # locked here!
        # ...
        user = session.query('User').filter(id='001').one()
        user.password = 'new password'
        session.commit()
        # ...
    pass
    # unlocked here!
    # ...
# ...

CHANGELOG

v0.2a1

Date: 2021-03-08

v0.1.2

Date: 2021-01-26

Still an early version, not for production.

  • Changes:
    • Arguments and it's default value of acquire now similar to stdlib's multiprossing.Lock, instead of Threading.Lock
    • MySQL lock now accepts float-point value as timeout
  • Adds
    • Several new test cases
  • Other
    • Many other small adjustment

v0.1.1

  • A very early version, maybe not stable enough.
  • Replace black2b with crc64-iso in PostgreSQL key convert function
  • Only named arguments as extra parameters allowed in Lock's implementation class

AUTHORS

Project details


Download files

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

Source Distribution

SQLAlchemy-DLock-0.2a1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SQLAlchemy_DLock-0.2a1-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file SQLAlchemy-DLock-0.2a1.tar.gz.

File metadata

  • Download URL: SQLAlchemy-DLock-0.2a1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for SQLAlchemy-DLock-0.2a1.tar.gz
Algorithm Hash digest
SHA256 2b466b6484dc39b26a16251a7c70efe4197d20710680a046d6e7b3af4041afe5
MD5 e8a117e2d308fc1b7575bfec99bd94c3
BLAKE2b-256 41bb52bb58125229783e152c7ab45c35b118cdb9dd2bb91dfb2b950fd855b1bb

See more details on using hashes here.

File details

Details for the file SQLAlchemy_DLock-0.2a1-py3-none-any.whl.

File metadata

  • Download URL: SQLAlchemy_DLock-0.2a1-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for SQLAlchemy_DLock-0.2a1-py3-none-any.whl
Algorithm Hash digest
SHA256 199f029bae25c0a9a0d995d71d1463d9257cbc5927218304bcbed704cf25efa7
MD5 4624f758472a384eb10a8a314bac7f25
BLAKE2b-256 4ed21a8c6003392b860422378582f7efef03f8c68010b332de31c7480e891e5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page