-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
74 lines (60 loc) · 1.87 KB
/
Copy pathrun.py
File metadata and controls
74 lines (60 loc) · 1.87 KB
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
"""
HIVEMIND Launcher — starts backend + frontend in one command.
Usage:
python run.py
"""
import sys
import os
import asyncio
import subprocess
import signal
ROOT = os.path.dirname(os.path.abspath(__file__))
BACKEND_DIR = os.path.join(ROOT, "backend")
FRONTEND_DIR = os.path.join(ROOT, "frontend")
BACKEND_PORT = int(os.getenv("PORT", "8081"))
FRONTEND_PORT = 5173
processes: list[subprocess.Popen] = []
def kill_all():
for p in processes:
try:
p.terminate()
except Exception:
pass
def main():
# Windows: use ProactorEventLoop for subprocess support
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
print(f"Starting HIVEMIND...")
print(f" Backend: http://localhost:{BACKEND_PORT}")
print(f" Frontend: http://localhost:{FRONTEND_PORT}")
print(f" Press Ctrl+C to stop both.\n")
# Start backend — use current Python interpreter (works on Mac venv + Windows conda)
backend = subprocess.Popen(
[sys.executable, "run.py"],
cwd=BACKEND_DIR,
)
processes.append(backend)
# Start frontend
npm_cmd = "npm.cmd" if sys.platform == "win32" else "npm"
frontend = subprocess.Popen(
[npm_cmd, "run", "dev"],
cwd=FRONTEND_DIR,
)
processes.append(frontend)
# Wait for either to exit, or Ctrl+C
try:
while True:
for p in processes:
ret = p.poll()
if ret is not None:
name = "Backend" if p == backend else "Frontend"
print(f"\n{name} exited with code {ret}. Stopping...")
kill_all()
sys.exit(ret)
import time
time.sleep(1)
except KeyboardInterrupt:
print("\nShutting down...")
kill_all()
if __name__ == "__main__":
main()