Skip to main content

Super simple file based locking

Project description

ezlock

Super simple file-based locking:

# first.py
from ezlock import Lock
import time

with Lock():
    print("I got the lock and I'm keeping it for 20s")
    time.sleep(20)

and

# second.py
...
with Lock():
    print("Trying to get a lock too")

running

>>> python3 first.py &
I got the lock and I'm keeping it for 20s
>>> echo "before 20s"
before 20s
>>> python3 second.py
locking.LockError: Attempted to acquire on already locked lock!

Lock files have an owner. A lock can check if it owns a file with lock.mine. Locks will only release a lock that's not theirs if it's forced i.e. lock.release(force=True).

You can wait for a lock to be released with Lock.wait()

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

ezlock-0.1.2.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

ezlock-0.1.2-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

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