DistributedLockPython Distributed Lock with memcached support | |
Download |
DistributedLock Ranking & Summary
Advertisement
- License:
- GPL v3
- Price:
- FREE
- Publisher Name:
- Silvano Buback
- Publisher web site:
- https://github.com/snbuback/
DistributedLock Tags
DistributedLock Description
DistributedLock is a Python distributed lock (currently only with memcached) module.How to configureIn your setup file (in django, settings.py), configure locking:pythonimport distributedlockdistributedlock.DEFAULT_MEMCACHED_CLIENT = memcache.Client()distributedlock.DEFAULT_TIMEOUT=60distributedlock.DEFAULT_BLOCKING=FalseIf you setting up memcached in Django, you can use it abstraction of memcached.pythonfrom django.core.cache import cachedistributedlock.DEFAULT_MEMCACHED_CLIENT = cacheYou can configure this settings in each lock, as parameter.How to useUsing minimal configuration, as decorator:pythonfrom distributedlock import distributedlock@distributedlock()def hello_world(): print 'running'Or as `with` block:pythonfrom distributedlock import distributedlock... my code beforewith distributedlock('hello'): print 'running'... my code afterYou can use with conventional threading.Lock (only in process locking)pythonfrom distributedlock import distributedlockimport threadingwith distributedlock('hello', lock=threading.Lock()) print 'running'Argumentspythondef distributedlock(key, lock=None, blocking=None) * key: name of key in memcached. Avoid long names, because memcached supports only 255 characters in key. Using decorator key name will be class name + method name if not specified. * lock: If you desire use another lock strategy, like `threading.Lock()` or `threading.RLock()`. defaults to `distributedlock.memcachedlock.MemcachedLock` * blocking: If another process has lock, wait until have a lock or abort immediately, raising `LockNotAcquiredError`. Defaults to `distributedlock.DEFAULT_BLOCKING`Product's homepage
DistributedLock Related Software