Skip to content

File-based locks for Python for Linux and Windows

License

Notifications You must be signed in to change notification settings

mrocklin/locket.py

 
 

Repository files navigation

locket.py

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()

About

File-based locks for Python for Linux and Windows

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 95.1%
  • Makefile 4.9%