File size: 1,085 Bytes
c2a61b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import subprocess, sys, os

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
os.chdir(PROJECT_ROOT)

# Kill anything on port 8080 before starting
try:
    r = subprocess.run(["netstat", "-ano"], capture_output=True, text=True)
    for line in r.stdout.splitlines():
        if ":8080 " in line and "LISTENING" in line:
            pid = int(line.strip().split()[-1])
            subprocess.run(["taskkill", "/F", "/PID", str(pid)], capture_output=True)
            print(f"Killed PID {pid} on port 8080")
except Exception:
    pass

env = os.environ.copy()
env["PYTHONIOENCODING"] = "utf-8"

# Prefer the local venv if it exists, otherwise fall back to whatever
# interpreter is currently running this script (so it doesn't hard-fail
# on a machine/path that doesn't have this exact .venv).
venv_python = os.path.join(PROJECT_ROOT, ".venv", "Scripts", "python.exe")
python = venv_python if os.path.exists(venv_python) else sys.executable

subprocess.run(
    [python, "-m", "uvicorn", "dashboard_backend.main:app",
     "--host", "127.0.0.1", "--port", "8080"],
    env=env
)