Package: globallock
globallockDistributed lock manager, support many types of backend, e.g. redis, django-redis, etcd, zookeeper...Installpip install globallockNotice: there're two l in globallock.RedisGlobalLock UsagefromgloballockimportGlobalLockManagerfromgloballockimportREDIS_GLOBAL_LOCK_CLASS# RedisGlobalLock is the default engine class,# so config item global_lock_engine_class is optional hereconfig={"global_lock_engine_class":REDIS_GLOBAL_LOCK_CLASS,# optional"global_lock_engine_options":{# redis connection pool init options goes here..."host":"xxx","port":6379,"password":"xxx","db":0,}}lockman=GlobalLockManager(config)lockname="your unique lock name"withlockman.lock(lockname,timeout=60,blocking=True,blocking_timeout=5)aslock:iflock.is_locked:pass# do something with lock...else:pass# do something without lock, mostly do NOTHING...DjangoRedisGlobalLock UsagefromgloballockimportGlobalLockManagerfromgloballockimportDJANGO_REDIS_GLOBAL_LOCK_CLASSconfig={"global_lock_engine_class":DJANGO_REDIS_GLOBAL_LOCK_CLASS,# required"global_lock_engine_options":{"redis-cache-name":"default",# redis-cache-name is default to `default`}}lockman=GlobalLockManager(config)lockname="your unique lock name"withlockman.lock(lockname,timeout=60,blocking=True,blocking_timeout=5)aslock:iflock.is_locked:pass# do something with lock...else:pass# do something without lock, mostly do NOTHING...EtcdGlobalLock UsagefromgloballockimportGlobalLockManagerfromgloballockimportETCD_GLOBAL_LOCK_CLASSconfig={"global_lock_engine_class":ETCD_GLOBAL_LOCK_CLASS,# required"global_lock_engine_options":{# etcd3 client init options goes here...}}lockman=GlobalLockManager(config)lockname="your unique lock name"withlockman.lock(lockname,timeout=60,blocking=True,blocking_timeout=5)aslock:iflock.is_locked:pass# do something with lock...else:pass# do something without lock, mostly do NOTHING...ZookeeperGlobalLock UsagefromgloballockimportGlobalLockManagerfromgloballockimportZOOKEEPER_GLOBAL_LOCK_CLASSconfig={"global_lock_engine_class":ZOOKEEPER_GLOBAL_LOCK_CLASS,# required"global_lock_engine_options":{# KazooClient init options goes here...}}lockman=GlobalLockManager(config)lockname="your unique lock name"withlockman.lock(lockname,blocking=True,blocking_timeout=5)aslock:iflock.is_locked:pass# do something with lock...else:pass# do something without lock, mostly do NOTHING...Notice:timeoutparameter forlockman.lock()will not work for ZookeeperGlobalLock.With ZookeeperGlobalLock, if the process which ownned the lock kill without any signal(kill -9), other process can acquire the lock after a short time(about 10 seconds after the lock-owner process killed). With other global lock engine, you have to wait the lock'stimeouteffect, after the the lock-owner process killed.Engine Class RequirementsRedisGlobalLock:pip install redisDjangRedisGlobalLock:pip install django-redisEtcdGlobalLock:You need to download the source code of etcd3 fromhttps://github.com/kragniz/python-etcd3, and install it with shell command (pip install .). You can NOT install it viapip install etcd3. The latest version of etcd3 installed via pip is 0.12.0, but it can not work with it's requires packages of latest version.Of course, if theetcd3package published in pypi upgraded, you can try to install it via pip command.Before theetcd3projects goes on and release new package to fix the problems, you canpip install zencore-etcd3instead.zencore-etcd3is just pull the latest source code ofetcd3formhttps://github.com/kragniz/python-etcd3, build it as pypi package and upload it to the pypi site.ZookeeperGlobalLock:pip install kazooNotice: The packages above are not added to the package's requirements.txt, so you need to install them by yourself, or put them into your projects' requirements.txt.Test Passed With Pythonspython36python37python38python39python310python311Releasesv0.1.0First release.Add RedisGlobalLock implementations.Add DjangoRedisGlobalLock implementations.Add EtcdGlobalLock implementations.Add ZookeeperGlobalLock implementations.v0.1.1Doc update.