""" Debug launcher for TraceStudio backend. Usage: python server/debug_run.py This script starts debugpy listener on port 5678 and then launches uvicorn. It waits for the debugger to attach before starting the application. """ import subprocess import sys import os def main(): # Ensure debugpy is installed try: import debugpy # type: ignore except Exception: print("debugpy is not installed. Please run: pip install debugpy") sys.exit(1) # Start debugpy listener in this process and wait for client import debugpy # type: ignore host = "0.0.0.0" port = 5678 print(f"Starting debugpy listener on {host}:{port}, waiting for client...") debugpy.listen((host, port)) debugpy.wait_for_client() print("Debugger attached, starting uvicorn...") # Launch uvicorn as module in the same process os.execv(sys.executable, [sys.executable, "-m", "uvicorn", "server.main:app", "--host", "127.0.0.1", "--port", "8000"]) if __name__ == "__main__": main()