-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_services.py
More file actions
54 lines (46 loc) · 1.41 KB
/
Copy pathstart_services.py
File metadata and controls
54 lines (46 loc) · 1.41 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
import os
import sys
import subprocess
import time
import threading
def run_service(command, name):
print(f"🚀 Starting {name}...")
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
shell=True
)
# Stream stdout/stderr
for line in process.stdout:
print(f"[{name}] {line.strip()}")
process.wait()
print(f"🛑 {name} stopped with exit code {process.returncode}")
if __name__ == "__main__":
# Ensure logs folder exists
os.makedirs("logs", exist_ok=True)
# 1. Start FastAPI API
api_cmd = f"{sys.executable} -m uvicorn src.api.app:app --host 0.0.0.0 --port 8000"
api_thread = threading.Thread(
target=run_service,
args=(api_cmd, "API-Backend"),
daemon=True
)
# 2. Start Streamlit App
streamlit_cmd = f"{sys.executable} -m streamlit run app.py --server.port 8501 --server.address 0.0.0.0"
streamlit_thread = threading.Thread(
target=run_service,
args=(streamlit_cmd, "Streamlit-Dashboard"),
daemon=True
)
api_thread.start()
time.sleep(3) # Give API a few seconds to start up
streamlit_thread.start()
try:
# Keep main thread alive
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nStopping all services...")
sys.exit(0)