radpid / run.py
yassonee's picture
Create run.py
064d5a9 verified
raw
history blame
1.08 kB
import subprocess
import sys
import time
from threading import Thread
import os
import signal
def run_fastapi():
print("Starting FastAPI server...")
subprocess.run([sys.executable, "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"])
def run_streamlit():
print("Starting Streamlit server...")
subprocess.run([sys.executable, "-m", "streamlit", "run", "app.py"])
def main():
# Start FastAPI in a separate thread
fastapi_thread = Thread(target=run_fastapi)
fastapi_thread.daemon = True
fastapi_thread.start()
# Give FastAPI a moment to start
time.sleep(2)
# Start Streamlit
streamlit_thread = Thread(target=run_streamlit)
streamlit_thread.daemon = True
streamlit_thread.start()
try:
# Keep the main thread alive
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nShutting down servers...")
# Send SIGTERM to the current process group
os.killpg(os.getpgid(0), signal.SIGTERM)
sys.exit(0)
if __name__ == "__main__":
main()