forked from fogsightai/fogsight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_fogsight.py
More file actions
39 lines (29 loc) · 901 Bytes
/
start_fogsight.py
File metadata and controls
39 lines (29 loc) · 901 Bytes
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
import webbrowser
import subprocess
import threading
import time
import os
HOST = "127.0.0.1"
PORT = 8000
def start_backend():
"""使用 subprocess 启动 uvicorn 服务器。"""
print(f"--- 后端启动中,请访问 http://{HOST}:{PORT} ---")
subprocess.run(
[os.sys.executable, "-m", "uvicorn", "app:app", f"--host={HOST}", f"--port={PORT}"]
)
def open_frontend():
"""在默认浏览器中打开前端页面。"""
time.sleep(2)
url = f"http://{HOST}:{PORT}"
print(f"--- 在默认浏览器中打开前端: {url} ---")
webbrowser.open(url)
if __name__ == "__main__":
backend_thread = threading.Thread(target=start_backend)
backend_thread.daemon = True
backend_thread.start()
open_frontend()
try:
backend_thread.join()
except KeyboardInterrupt:
print("\n--- 程序已关闭 ---")
os._exit(0)