Distributed lock manager for Python

后端 未结 4 1769
-上瘾入骨i
-上瘾入骨i 2020-11-30 06:57

I have a bunch of servers with multiple instances accessing a resource that has a hard limit on requests per second.

I need a mechanism to lock the access on this re

4条回答
  •  無奈伤痛
    2020-11-30 07:28

    For my cluster I'm using ZooKeeper with python-kazoo library for queues and locks.

    Modified example from kazoo api documentation for your purpose: http://kazoo.readthedocs.org/en/latest/api/recipe/lock.html

    zk = KazooClient()
    lock = zk.Lock("/lockpath", "my-identifier")
    if lock.acquire(timeout=1):
    
       code here
    
       lock.release()
    

    But you need at least three nodes for ZooKeeper as I remember.

提交回复
热议问题