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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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