Process lock



alias of fasteners.process_lock._FcntlLock

class fasteners.process_lock._InterProcessLock(path, sleep_func=<built-in function sleep>, logger=None)

An interprocess locking implementation.

This is a lock implementation which allows multiple locks, working around issues like and does not require any cleanup. Since the lock is always held on a file descriptor rather than outside of the process, the lock gets dropped automatically if the process crashes, even if __exit__ is not executed.

There are no guarantees regarding usage by multiple threads in a single process here. This lock works only between processes.

Note these locks are released when the descriptor is closed, so it’s not safe to close the file descriptor while another thread holds the lock. Just opening and closing the lock file can break synchronization, so lock files must be accessed only using this abstraction.


It is quite useful to read before using (to understand the risks involved):

acquire(blocking=True, delay=0.01, max_delay=0.1, timeout=None)

Attempt to acquire the given lock.

  • blocking (bool) – whether to wait forever to try to acquire the lock
  • delay (int/float) – when blocking this is the delay time in seconds that will be added after each failed acquisition
  • max_delay (int/float) – the maximum delay to have (this limits the accumulated delay(s) added after each failed acquisition)
  • timeout (int/float) – an optional timeout (limits how long blocking will occur for)

whether or not the acquisition succeeded

Return type:



Checks if the path that this lock exists at actually exists.


Release the previously acquired lock.



Acquires & releases a interprocess lock around call into decorated function.