Skip to main content

Mutex implementation for distributed systems.

Project description

dimutex

Python library implementing asyncio-based distributed mutex on top of different providers.

Mutex is a synchronization primitive used to ensure that only one worker can do the given job. It can be used for safe access to a shared resource or for distributing tasks among multiple workers.

Currently, the only implemented provider is GCS (Google Cloud Storage). The implementation is based on the algorithm described in article A robust distributed locking algorithm based on Google Cloud Storage (see also Ruby implementation).

Features

  • Asynchronous.
  • Type-safe.
  • Atomic.
  • Expiration mechanism to ensure that a single worker won't hold the lock forever.
  • Supports emulators.

Installation

python3 -m pip install dimutex

Usage

import dimutex

async def do_something():
    lock = dimutex.GCS(bucket='bucket-name', name='lock-name')
    async with lock:
        try:
            await lock.acquire()
        except dimutex.AlreadyAcquiredError:
            return 'already acquired'
        try:
            ... # do something with the shared resuource
        finally:
            await lock.release()

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

dimutex-1.3.1.tar.gz (8.1 kB view hashes)

Uploaded Source

Built Distribution

dimutex-1.3.1-py3-none-any.whl (5.8 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