Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

local mutex

Project Description
#local_mutex
本地锁,通过fcntl针对文件加锁实现的. 需要强烈注意的是,多线程下是无效的,原因? [查看链接](http://xiaorui.cc)

#Usage:

最简单的例子,适合一个程序同时跑一个的场景.
```
import sys
from local_mutex import LocalMutex

try:
lock = LocalMutex('app.lock')
except LockError:
sys.exit('already running')

try:
print 'doing'
finally:
lock.release()
```

使用wait参数不停的试图获取Lock, 直到获取锁.
```
lock = LocalMutex('/var/run/app.lock', wait = True)
try:
print 'doing'
finally:
lock.release()
```

使用with关键词
```
with LocalMutex('app.lock', wait = True):
print 'doing'
```

如果是多线程环境,直接用threading的Lock
```
import threading
lock = threading.Lock()
with lock:
pass
```
Release History

Release History

This version
History Node

1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
local_mutex-1.0.tar.gz (2.3 kB) Copy SHA256 Checksum SHA256 Source Nov 29, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS 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