maple.utils.lock

Daemon locking utilities.

This module provides Unix socket-based locking to ensure only one instance of the MAPLE daemon runs at a time. It uses filesystem Unix domain sockets as a locking mechanism, which automatically releases when a process terminates.

Key features: - Single daemon instance enforcement - Automatic stale lock detection and cleanup - Context manager support for RAII pattern - Socket liveness checking - Runtime directory support (XDG_RUNTIME_DIR)

The DaemonLock class uses bind() semantics on Unix sockets - only one process can bind to a socket path at a time. This provides a reliable, OS-level locking mechanism that automatically releases if the daemon crashes.

Classes

DaemonLock([socket_path])

Unix socket-based lock for ensuring single daemon instance.

Functions

get_socket_path()

Get the default daemon socket path.

is_daemon_running([socket_path])

Check if the MAPLE daemon is currently running.