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 )