maple.utils.lock.DaemonLock

class maple.utils.lock.DaemonLock(socket_path: Path = None)

Unix socket-based lock for ensuring single daemon instance.

Implements a file-based locking mechanism using Unix domain sockets. Only one process can bind to a socket path at a time, providing reliable mutex semantics. The lock automatically releases when the process terminates, preventing permanent lock files.

The class detects and removes stale locks (socket files that exist but no process is listening on them) to handle crash recovery.

Supports context manager protocol for automatic lock acquisition and release using the ‘with’ statement.

Methods

__init__([socket_path])

Initialize the DaemonLock.

acquire()

Attempt to acquire the daemon lock.

release()

Release the daemon lock.