MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / check_pid_file

Function check_pid_file

core/daemon.py:46–65  ·  view source on GitHub ↗

Check if daemon is already running. Returns True if another daemon is running. Removes stale PID file if process is dead.

()

Source from the content-addressed store, hash-verified

44# ==================== PID File Management ====================
45
46def check_pid_file() -> bool:
47 """
48 Check if daemon is already running.
49
50 Returns True if another daemon is running.
51 Removes stale PID file if process is dead.
52 """
53 if PID_FILE.exists():
54 try:
55 pid = int(PID_FILE.read_text().strip())
56 os.kill(pid, 0) # Signal 0 checks if process exists
57 return True # Daemon is running
58 except PermissionError:
59 return True # Process exists but owned by another user — treat as running
60 except (ProcessLookupError, ValueError):
61 # Process is dead or PID file is corrupt — remove stale file
62 warning("Removing stale PID file")
63 PID_FILE.unlink(missing_ok=True)
64 return False
65 return False
66
67
68def write_pid_file():

Callers 3

_daemon_is_runningFunction · 0.90
mainFunction · 0.90
mainFunction · 0.85

Calls 2

warningFunction · 0.90
existsMethod · 0.80

Tested by

no test coverage detected