Skip to main content

File-based locks for Python for Linux and Windows

Project description

import locket

# Wait for lock
with locket.lock_file("path/to/lock/file"):
    perform_action()

# Raise error if lock cannot be acquired immediately
with locket.lock_file("path/to/lock/file", timeout=0):
    perform_action()

# Raise error if lock cannot be acquired after thirty seconds
with locket.lock_file("path/to/lock/file", timeout=30):
    perform_action()

# Without context managers:
lock = locket.lock_file("path/to/lock/file")
try:
    lock.acquire()
    perform_action()
finally:
    lock.release()

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

locket-0.1.1.tar.gz (1.6 kB view hashes)

Uploaded Source

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