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()
forked from mwilliamson/locket.py
-
Notifications
You must be signed in to change notification settings - Fork 0
File-based locks for Python for Linux and Windows
License
mrocklin/locket.py
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
File-based locks for Python for Linux and Windows
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published
Languages
- Python 95.1%
- Makefile 4.9%