跳转到主要内容

分布式系统互斥锁实现。

项目描述

dimutex

在多个提供者之上实现基于asyncio的分布式互斥锁的Python库。

互斥锁是一种同步原语,用于确保只有一个工作进程可以执行给定的任务。它可以用于安全地访问共享资源或将任务分配给多个工作进程。

目前,唯一实现的提供者是GCS(Google Cloud Storage)。该实现基于文章基于Google Cloud Storage的健壮分布式锁定算法(另见Ruby实现)中描述的算法。

功能

  • 异步。
  • 类型安全。
  • 原子。
  • 到期机制确保单个工作进程不会永久持有锁。
  • 支持模拟器。

安装

python3 -m pip install dimutex

使用

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

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分布

dimutex-1.3.1.tar.gz (8.1 kB 查看哈希值)

上传于

构建分布

dimutex-1.3.1-py3-none-any.whl (5.8 kB 查看哈希值)

上传于 Python 3

由以下支持