Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orsinium-labs/dimutex
asyncio Python library for distributed mutex with GCS as a backend
https://github.com/orsinium-labs/dimutex
distributed-systems gcp gcs google-cloud google-cloud-platform google-cloud-storage mutex python
Last synced: about 2 months ago
JSON representation
asyncio Python library for distributed mutex with GCS as a backend
- Host: GitHub
- URL: https://github.com/orsinium-labs/dimutex
- Owner: orsinium-labs
- License: mit
- Created: 2022-02-24T12:56:00.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-24T13:06:32.000Z (almost 3 years ago)
- Last Synced: 2024-11-13T19:09:08.592Z (about 2 months ago)
- Topics: distributed-systems, gcp, gcs, google-cloud, google-cloud-platform, google-cloud-storage, mutex, python
- Language: Python
- Homepage:
- Size: 21.5 KB
- Stars: 15
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dimutex
Python library implementing [asyncio][asyncio]-based distributed mutex on top of different providers.
[Mutex][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][gcs-algo] (see also [Ruby implementation][ruby]).
[asyncio]: https://docs.python.org/3/library/asyncio.html
[mutex]: https://stackoverflow.com/questions/34524/what-is-a-mutex
[gcs-algo]: https://www.joyfulbikeshedding.com/blog/2021-05-19-robust-distributed-locking-algorithm-based-on-google-cloud-storage.html
[ruby]: https://github.com/FooBarWidget/distributed-lock-google-cloud-storage-ruby## Features
+ Asynchronous.
+ Type-safe.
+ Atomic.
+ Expiration mechanism to ensure that a single worker won't hold the lock forever.
+ Supports emulators.## Installation
```bash
python3 -m pip install dimutex
```## Usage
```python
import dimutexasync def do_something():
lock = dimutex.GCS(bucket='bucket-name', name='lock-name')
# context manager makes sure to close aiohttp session
async with lock:
try:
await lock.acquire()
except dimutex.AlreadyAcquiredError:
return 'already acquired'
try:
# do something with the shared resource
...
# update expiration if you need more time
await lock.refresh()
...
finally:
await lock.release()
```