Locket implements a file-based lock that can be used by multiple processes provided they use the same path.
import locket # Wait for lock with locket.lock_file("path/to/lock/file"): perform_action() # Raise LockError if lock cannot be acquired immediately with locket.lock_file("path/to/lock/file", timeout=0): perform_action() # Raise LockError 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()
Locks largely behave as (non-reentrant) Lock
instances from the threading
module in the standard library. Specifically, their behaviour is:
acquire()
returns immediately and changes the lock state to locked.acquire()
will block until the lock state changes to unlocked, or until the timeout expires.release()
to change the state to unlocked.release()
on an unlocked lock raises LockError
.fork
is undefined.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4