Spaces:
Sleeping
Sleeping
File size: 1,956 Bytes
906e104 | 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #!/usr/bin/env python3
"""
start.py — Launch the DAHS_2 app (backend + frontend, single server)
Usage: python start.py
Then open: http://localhost:8000
"""
import shutil
import subprocess
import sys
import time
import webbrowser
from pathlib import Path
ROOT = Path(__file__).parent.resolve()
PORT = 8000
PYTHON_CANDIDATES = [
p for p in [
sys.executable,
shutil.which("python3"),
shutil.which("python"),
] if p
]
def find_python() -> str:
for py in PYTHON_CANDIDATES:
p = Path(py)
if not p.exists():
continue
result = subprocess.run(
[str(p), "-c", "import fastapi, uvicorn"],
capture_output=True, timeout=5
)
if result.returncode == 0:
return str(p)
return sys.executable
def main() -> None:
python = find_python()
print(f"\n DAHS 2.0 — Disruption-Aware Hybrid Scheduler")
print(f" Using Python: {python}\n")
proc = subprocess.Popen(
[python, "-m", "uvicorn", "server:app",
"--host", "0.0.0.0", "--port", str(PORT),
"--ws-max-size", "16777216"],
cwd=str(ROOT),
)
print(f" Starting server…")
time.sleep(3)
if proc.poll() is not None:
print(f"\n ERROR: Server exited immediately (code {proc.returncode}).")
print(f" Try running manually:\n")
print(f" {python} -m uvicorn server:app --port {PORT}\n")
sys.exit(1)
url = f"http://localhost:{PORT}"
print(f" Website: {url}")
print(f" API: {url}/health")
print(f"\n Opening browser… (Press Ctrl+C to stop)\n")
webbrowser.open(url)
try:
proc.wait()
except KeyboardInterrupt:
print("\n Shutting down…")
proc.terminate()
try:
proc.wait(timeout=5)
except subprocess.TimeoutExpired:
proc.kill()
print(" Done.")
if __name__ == "__main__":
main()
|