mt.base.locket
File-based resource lock that can be used by multiple processes provided they use the same path.
Example
``` from mt.base 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()
See also
https
//github.com/mwilliamson/locket.py
Functions
lock_file()
: Undocumented.
- mt.base.locket.lock_file(path, **kwargs)