-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunme.py
More file actions
53 lines (44 loc) · 1.57 KB
/
runme.py
File metadata and controls
53 lines (44 loc) · 1.57 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
import os
import multiprocessing
import sys
def run_fastapi():
"""运行 FastAPI 后端服务"""
os.system("uvicorn app.main:app --host 0.0.0.0 --port 8001")
def run_flask():
"""运行 Flask admin system"""
# 添加项目根目录到 Python 路径
root_path = os.path.dirname(os.path.abspath(__file__))
admin_path = os.path.join(root_path, 'admin_system')
os.environ['PYTHONPATH'] = admin_path
# 导入 Flask 应用
from admin_system.run import app
app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False)
if __name__ == "__main__":
# 设置多进程启动方法(在 Windows 上需要)
multiprocessing.freeze_support()
# 创建进程
fastapi_process = multiprocessing.Process(target=run_fastapi)
flask_process = multiprocessing.Process(target=run_flask)
try:
# 启动进程
fastapi_process.start()
flask_process.start()
print("FastAPI running on http://localhost:8001")
print("Admin System running on http://localhost:5000")
# 等待进程结束
fastapi_process.join()
flask_process.join()
except KeyboardInterrupt:
# 处理 Ctrl+C
print("\nShutting down servers...")
fastapi_process.terminate()
flask_process.terminate()
# 等待进程完全结束
fastapi_process.join()
flask_process.join()
print("Servers stopped")
except Exception as e:
print(f"Error occurred: {e}")
fastapi_process.terminate()
flask_process.terminate()
raise