This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
#pyetcdlock

基于etcd的分布式锁,简单说就是利用etcd.test_and_set函数来判断lock key是否被占用,存在那就说明有人占用。在创建key的时候加入了ttl,防止因为进程异常退出而没有释放锁。

更新日志:

加入watch机制,更快的解决了etcd客户端因为异常退出后,key需要等待ttl过期的问题。简单说,模拟了zookeeper那种临时节点的概念。


**曾经写过关于分布式互斥锁的文章:**

zookeeper:
[http://xiaorui.cc/2015/04/09/python-zookeeper%E8%A7%A3%E5%86%B3redis%E5%81%9A%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81%E5%B8%A6%E6%9D%A5%E7%9A%84%E5%9D%91/](http://xiaorui.cc/2015/04/09/python-zookeeper%E8%A7%A3%E5%86%B3redis%E5%81%9A%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81%E5%B8%A6%E6%9D%A5%E7%9A%84%E5%9D%91/)

redis:
[http://xiaorui.cc/2014/12/19/python%E4%BD%BF%E7%94%A8redis%E5%AE%9E%E7%8E%B0%E5%8D%8F%E5%90%8C%E6%8E%A7%E5%88%B6%E7%9A%84%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81/](http://xiaorui.cc/2014/12/19/python%E4%BD%BF%E7%94%A8redis%E5%AE%9E%E7%8E%B0%E5%8D%8F%E5%90%8C%E6%8E%A7%E5%88%B6%E7%9A%84%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81/)

### 安装方法

```
git clone https://github.com/rfyiamcool/pyetcdlock.git
cd pyetcdlock
python setup.py
```

pypi的安装方式 (话说,pypi有些问题,你在pypi search搜东西的时候,不显示详细信息)

```
pip instlal pyetcdlock
```

模块说明:

ttl : expire过期时间,这样可以指定锁定的时间

renew : 如果你的ttl时间将要过期了,那么可以使用renew(),再加点锁定的ttl时间

force_acquire : 强制获取锁


### 创建连接

```
import etcd
from pyetcdnetlock import Lock

client = client = etcd.Client(host='127.0.0.1')
lock = Lock(client, 'path/to/my/key', ttl=30, renewSecondsPrior=5)
```

### 使用方法

```
if lock.acquire(timeout=20):
# some work
lock.renew()
# some other work
lock.release()
else
# failed to acquire the lock in 20 seconds
pass

```

OR

```
with lock as l:
#如果时间不够,可以用renew()参数,加点时间
l.renew()
# some other work
```
Release History

Release History

1.2.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pyetcdlock-1.2.0.tar.gz (3.6 kB) Copy SHA256 Checksum SHA256 Source Sep 13, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting