darkmedia-x-api / backend /api /list_started_processes.py
cybermedia's picture
Upload folder using huggingface_hub
343eed9 verified
#!/usr/bin/env python3
"""
scripts/list_started_processes.py
Utility to list the processes that were started by ``start_all.py``.
It looks for the command‑line strings that ``start_all.py`` uses to launch
the AI backend, Ollama, the FastAPI dashboard and the desktop shortcut.
Run it after ``python start_all.py``:
python scripts/list_started_processes.py
"""
import sys
import os
from pathlib import Path
# psutil gives us a cross‑platform way to inspect running processes.
try:
import psutil
except ImportError:
print("[*] Installing psutil …")
import subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "psutil"])
import psutil
# ----------------------------------------------------------------------
# Identifiers that match the commands used in start_all.py
# ----------------------------------------------------------------------
IDENTIFIERS = [
# AI backend (StabilityMatrix or generic python backend)
"StabilityMatrix",
"START_AI_BACKEND",
# Ollama service
"ollama",
# FastAPI dashboard server
"dashboard_server.py",
# Desktop shortcut (just for completeness – not a process)
"DARKMEDIA-X STUDIO",
]
def is_match(proc):
"""Return True if any identifier appears in the process name or cmdline."""
try:
name = proc.name().lower()
cmd = " ".join(proc.cmdline()).lower()
for ident in IDENTIFIERS:
ident_lc = ident.lower()
if ident_lc in name or ident_lc in cmd:
return True
except (psutil.NoSuchProcess, psutil.AccessDenied):
return False
return False
def main():
print("\n=== Processes started by start_all.py ===\n")
matches = [p for p in psutil.process_iter(['pid', 'name', 'cmdline']) if is_match(p)]
if not matches:
print("⚠️ No matching processes were found. Did you run start_all.py?")
return
for proc in matches:
try:
pid = proc.pid
name = proc.name()
cmd = " ".join(proc.cmdline())
print(f"[{pid}] {name}")
print(f" cmd: {cmd}")
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue
print("\n=== End of list ===\n")
if __name__ == "__main__":
main()