Skip to main content

Pure Python wrapper for elock distributed locking server.

Project description

=======
PyElock
=======

Pure Python wrapper for https://github.com/dustin/elock .

elock is "A simple, fault-tolerant distributed lock server in erlang." Using
it in Python allows you to do all sorts of cool stuff, like ensuring a Celery
task doesn't run more than once simultaneously, even across different Celery
servers.

Note, if you are already using Twisted in your project, you should check out
dustin's wrapper at https://github.com/dustin/elock-twisted .

Usage
=====

Simple single lock:

try:
with pyelock.ELockSingle(('remote-server.domain.com', 11400), 'my_lock'):
# Do some stuff
time.sleep(10)
except pyelock.LockInUse:
print "Can't do stuff, my_lock is in use"

If you want precise control over your locking behavior, or want to acquire
multiple locks, use the following code:

with pyelock.ELock(('remote-server.domain.com', 11400)) as elock:
# Acquire a lock, waiting up to 30 seconds for it
if not elock.lock('my_lock', timeout=30.0):
print "Oh no, can't get my_lock"

# Acquire another lock, without waiting if it's locked
if not elock.lock('my_other_lock'):
print "Can't get my_other_lock"

# Do some stuff...

# Release first lock
elock.unlock('my_lock')

# Do some other stuff...

# Note: you don't technically need to release locks right before the end
# of the 'with' block, since all locks held will be automatically released
# when the object is destroyed.

Project details


Download files

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

Source Distribution

PyELock-1.0.0.zip (3.8 kB view details)

Uploaded Source

File details

Details for the file PyELock-1.0.0.zip.

File metadata

  • Download URL: PyELock-1.0.0.zip
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyELock-1.0.0.zip
Algorithm Hash digest
SHA256 2d31d8ab766d2328cd9880764383ce83e599bbcb0dce13331e76db18364510df
MD5 80185ca11da8d17d74c7e8d4797a97a8
BLAKE2b-256 aab9c02d0e68f7a89ea32db40d172236f555c6c087e3b590a44d63b3e86bb1f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page