Skip to main content

Package to used for handling lock mechanism when running appplication with multiple replicas

Project description

python-distributed-lock module

This Python package provides a mechanism to acquire and release Redis and MYSQL locks with authentication. It is useful for ensuring that only one process can access a particular resource or execute a critical section of code at a time.

Features

  • Connects to Redis or MySQL with username and password for authentication.
  • Acquires a lock, executes a function, and then releases the lock.
  • Useful in distributed systems where resource locking is needed.

Installation

To install the module, use pip:

pip install pythonLock

Please check your database connection before passing it to module

use with mysql lock


from pythonLock import start_cron_with_expression

mysql_user = "root"
mysql_pass = "root"
mysql_host = "localhost"
mysql_database = "mysql"

connection = mysql.connector.connect(
    host=mysql_host,
    user=mysql_user,
    password=mysql_pass,
    database=mysql_database,
    pool_name="mypool",
    pool_size=3
)

cron_expression = "* */5 * * *"  # Runs every 5 minute
start_cron_with_expression(connection, my_custom_function, cron_expression,"mysql")


def my_custom_function():
    # add whatever action you want in your custom function
    pass

use with redis lock


from pythonLock import start_cron_with_expression

redis_host = "localhost"
redis_port = 6379
redis_username = "default"
redis_password = "root"

# Connect to Redis with username and password
connection = redis.StrictRedis(
    host=redis_host,
    port=redis_port,
    username=redis_username,
    password=redis_password,
    decode_responses=True
)

cron_expression = "* */5 * * *"  # Runs every 5 minute
start_cron_with_expression(connection, my_custom_function, cron_expression,"redis")


def my_custom_function():
    # add whatever action you want in your custom function
    pass

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

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

Source Distribution

pythonlock-1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

pythonLock-1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file pythonlock-1.0.tar.gz.

File metadata

  • Download URL: pythonlock-1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pythonlock-1.0.tar.gz
Algorithm Hash digest
SHA256 590a9a6b0d0e194d4f0683b131870e70c02a0c0c71885854e511d1d458af044d
MD5 2ceb7c55cc7caca60257471694dddb55
BLAKE2b-256 b306508677d535f82b41c80ae6a49b63f92a616ce9ad95e619d6a10545b45c83

See more details on using hashes here.

File details

Details for the file pythonLock-1.0-py3-none-any.whl.

File metadata

  • Download URL: pythonLock-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pythonLock-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db4eb04159d50140a1d6a9279ba57de8170d5194854fabf354fde799f8c49148
MD5 dee3ebe6dd2688b73fb3743f57f86133
BLAKE2b-256 8782a16ca78f7fdaf0bf1ba35d793bd156e3904456a7618d515f46b753a28a1c

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