# globallock
Distributed lock manager, support many types of backend, e.g. redis, django-redis, etcd, zookeeper...
## Install
```
pip install globallock
```
*Notice: there're two l in globallock.*
## RedisGlobalLock Usage
```python
from globallock import GlobalLockManager
from globallock import REDIS_GLOBAL_LOCK_CLASS
# RedisGlobalLock is the default engine class,
# so config item global_lock_engine_class is optional here
config = {
"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"
with lockman.lock(lockname, timeout=60, blocking=True, blocking_timeout=5) as lock:
if lock.is_locked:
pass # do something with lock...
else:
pass # do something without lock, mostly do NOTHING...
```
## DjangoRedisGlobalLock Usage
```python
from globallock import GlobalLockManager
from globallock import DJANGO_REDIS_GLOBAL_LOCK_CLASS
config = {
"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"
with lockman.lock(lockname, timeout=60, blocking=True, blocking_timeout=5) as lock:
if lock.is_locked:
pass # do something with lock...
else:
pass # do something without lock, mostly do NOTHING...
```
## EtcdGlobalLock Usage
```python
from globallock import GlobalLockManager
from globallock import ETCD_GLOBAL_LOCK_CLASS
config = {
"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"
with lockman.lock(lockname, timeout=60, blocking=True, blocking_timeout=5) as lock:
if lock.is_locked:
pass # do something with lock...
else:
pass # do something without lock, mostly do NOTHING...
```
## ZookeeperGlobalLock Usage
```python
from globallock import GlobalLockManager
from globallock import ZOOKEEPER_GLOBAL_LOCK_CLASS
config = {
"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"
with lockman.lock(lockname, blocking=True, blocking_timeout=5) as lock:
if lock.is_locked:
pass # do something with lock...
else:
pass # do something without lock, mostly do NOTHING...
```
*Notice:*
- `timeout` parameter for `lockman.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's `timeout` effect, after the the lock-owner process killed.
## Engine Class Requirements
- RedisGlobalLock:
* `pip install redis`
- DjangRedisGlobalLock:
* `pip install django-redis`
- EtcdGlobalLock:
* You need to download the source code of etcd3 from `https://github.com/kragniz/python-etcd3`, and install it with shell command (`pip install .`). You can NOT install it via `pip 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 the `etcd3` package published in pypi upgraded, you can try to install it via pip command.
* Before the `etcd3` projects goes on and release new package to fix the problems, you can `pip install zencore-etcd3` instead. `zencore-etcd3` is just pull the latest source code of `etcd3` form `https://github.com/kragniz/python-etcd3`, build it as pypi package and upload it to the pypi site.
- ZookeeperGlobalLock:
* `pip install kazoo`
*Notice: 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 Pythons
- python36
- python37
- python38
- python39
- python310
- python311
## Releases
### v0.1.0
- First release.
- Add RedisGlobalLock implementations.
- Add DjangoRedisGlobalLock implementations.
- Add EtcdGlobalLock implementations.
- Add ZookeeperGlobalLock implementations.
### v0.1.1
- Doc update.
### v0.1.2
- GlobalLockManager.lock方法参数可以在初始化时设置。
- 添加globallock.django.get_default_global_lock_manager方法,允许在django中使用全局分布式锁。
### v0.1.3
- 修正globallock.django默认设置。
Raw data
{
"_id": null,
"home_page": null,
"name": "globallock",
"maintainer": "Sun HuiBin",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "sunhuibin@zencore.cn",
"keywords": "global lock, distributed lock, redis lock, django redis lock, zookeeper lock, etcd lock",
"author": "Sun HuiBin",
"author_email": "sunhuibin@zencore.cn",
"download_url": "https://files.pythonhosted.org/packages/04/50/e396e92a9331d9958015bd4e12f283188be01daa9a8869cb2dc57cf867e8/globallock-0.1.3.tar.gz",
"platform": null,
"description": "# globallock\n\nDistributed lock manager, support many types of backend, e.g. redis, django-redis, etcd, zookeeper...\n\n## Install\n\n```\npip install globallock\n```\n\n*Notice: there're two l in globallock.*\n\n## RedisGlobalLock Usage\n\n```python\nfrom globallock import GlobalLockManager\nfrom globallock import REDIS_GLOBAL_LOCK_CLASS\n# RedisGlobalLock is the default engine class,\n# so config item global_lock_engine_class is optional here\nconfig = {\n \"global_lock_engine_class\": REDIS_GLOBAL_LOCK_CLASS, # optional\n \"global_lock_engine_options\": {\n # redis connection pool init options goes here...\n \"host\": \"xxx\",\n \"port\": 6379,\n \"password\": \"xxx\",\n \"db\": 0,\n }\n}\nlockman = GlobalLockManager(config)\nlockname = \"your unique lock name\"\nwith lockman.lock(lockname, timeout=60, blocking=True, blocking_timeout=5) as lock:\n if lock.is_locked:\n pass # do something with lock...\n else:\n pass # do something without lock, mostly do NOTHING...\n\n```\n\n## DjangoRedisGlobalLock Usage\n\n\n```python\nfrom globallock import GlobalLockManager\nfrom globallock import DJANGO_REDIS_GLOBAL_LOCK_CLASS\nconfig = {\n \"global_lock_engine_class\": DJANGO_REDIS_GLOBAL_LOCK_CLASS, # required\n \"global_lock_engine_options\": {\n \"redis-cache-name\": \"default\", # redis-cache-name is default to `default`\n }\n}\nlockman = GlobalLockManager(config)\nlockname = \"your unique lock name\"\nwith lockman.lock(lockname, timeout=60, blocking=True, blocking_timeout=5) as lock:\n if lock.is_locked:\n pass # do something with lock...\n else:\n pass # do something without lock, mostly do NOTHING...\n\n```\n\n## EtcdGlobalLock Usage\n\n```python\nfrom globallock import GlobalLockManager\nfrom globallock import ETCD_GLOBAL_LOCK_CLASS\nconfig = {\n \"global_lock_engine_class\": ETCD_GLOBAL_LOCK_CLASS, # required\n \"global_lock_engine_options\": { \n # etcd3 client init options goes here...\n }\n}\nlockman = GlobalLockManager(config)\nlockname = \"your unique lock name\"\nwith lockman.lock(lockname, timeout=60, blocking=True, blocking_timeout=5) as lock:\n if lock.is_locked:\n pass # do something with lock...\n else:\n pass # do something without lock, mostly do NOTHING...\n\n```\n\n## ZookeeperGlobalLock Usage\n\n```python\nfrom globallock import GlobalLockManager\nfrom globallock import ZOOKEEPER_GLOBAL_LOCK_CLASS\nconfig = {\n \"global_lock_engine_class\": ZOOKEEPER_GLOBAL_LOCK_CLASS, # required\n \"global_lock_engine_options\": { \n # KazooClient init options goes here...\n }\n}\nlockman = GlobalLockManager(config)\nlockname = \"your unique lock name\"\nwith lockman.lock(lockname, blocking=True, blocking_timeout=5) as lock:\n if lock.is_locked:\n pass # do something with lock...\n else:\n pass # do something without lock, mostly do NOTHING...\n\n```\n*Notice:*\n\n- `timeout` parameter for `lockman.lock()` will not work for ZookeeperGlobalLock.\n- 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's `timeout` effect, after the the lock-owner process killed.\n\n\n## Engine Class Requirements\n\n- RedisGlobalLock:\n * `pip install redis`\n- DjangRedisGlobalLock: \n * `pip install django-redis`\n- EtcdGlobalLock:\n * You need to download the source code of etcd3 from `https://github.com/kragniz/python-etcd3`, and install it with shell command (`pip install .`). You can NOT install it via `pip 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.\n * Of course, if the `etcd3` package published in pypi upgraded, you can try to install it via pip command.\n * Before the `etcd3` projects goes on and release new package to fix the problems, you can `pip install zencore-etcd3` instead. `zencore-etcd3` is just pull the latest source code of `etcd3` form `https://github.com/kragniz/python-etcd3`, build it as pypi package and upload it to the pypi site.\n- ZookeeperGlobalLock:\n * `pip install kazoo`\n\n*Notice: 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.*\n\n## Test Passed With Pythons\n\n- python36\n- python37\n- python38\n- python39\n- python310\n- python311\n\n## Releases\n\n### v0.1.0\n\n- First release.\n- Add RedisGlobalLock implementations.\n- Add DjangoRedisGlobalLock implementations.\n- Add EtcdGlobalLock implementations.\n- Add ZookeeperGlobalLock implementations.\n\n### v0.1.1\n\n- Doc update.\n\n### v0.1.2\n\n- GlobalLockManager.lock\u65b9\u6cd5\u53c2\u6570\u53ef\u4ee5\u5728\u521d\u59cb\u5316\u65f6\u8bbe\u7f6e\u3002\n- \u6dfb\u52a0globallock.django.get_default_global_lock_manager\u65b9\u6cd5\uff0c\u5141\u8bb8\u5728django\u4e2d\u4f7f\u7528\u5168\u5c40\u5206\u5e03\u5f0f\u9501\u3002\n\n### v0.1.3\n\n- \u4fee\u6b63globallock.django\u9ed8\u8ba4\u8bbe\u7f6e\u3002\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Distributed lock manager, support many types of backend, e.g. redis, django-redis, etcd, zookeeper...",
"version": "0.1.3",
"project_urls": null,
"split_keywords": [
"global lock",
" distributed lock",
" redis lock",
" django redis lock",
" zookeeper lock",
" etcd lock"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "29aee5eeb67cba7abb0e7ff51b409f3143148d9b12c2b1d83a3b900c306e0584",
"md5": "b912b04e7e704a477bdcd9818c3b59d0",
"sha256": "ddc04688171cd3b8f38eee04395cce16c6589fa7d59ae7a1e127e5fcf45fa4be"
},
"downloads": -1,
"filename": "globallock-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b912b04e7e704a477bdcd9818c3b59d0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 10231,
"upload_time": "2024-04-02T13:41:03",
"upload_time_iso_8601": "2024-04-02T13:41:03.577823Z",
"url": "https://files.pythonhosted.org/packages/29/ae/e5eeb67cba7abb0e7ff51b409f3143148d9b12c2b1d83a3b900c306e0584/globallock-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0450e396e92a9331d9958015bd4e12f283188be01daa9a8869cb2dc57cf867e8",
"md5": "e268d30ee93028a98f25c38fedf06a01",
"sha256": "cd0cf3c9101cec5cca0f97b5ac0be5d0158f478af78dc593f41b1436195bbf7c"
},
"downloads": -1,
"filename": "globallock-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "e268d30ee93028a98f25c38fedf06a01",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8910,
"upload_time": "2024-04-02T13:41:05",
"upload_time_iso_8601": "2024-04-02T13:41:05.215864Z",
"url": "https://files.pythonhosted.org/packages/04/50/e396e92a9331d9958015bd4e12f283188be01daa9a8869cb2dc57cf867e8/globallock-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-02 13:41:05",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "globallock"
}