66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
|
|
"""
|
|||
|
|
测试启动脚本 - 简单版本
|
|||
|
|
|
|||
|
|
先启动服务器,等待一段时间后启动客户端
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import subprocess
|
|||
|
|
import sys
|
|||
|
|
import time
|
|||
|
|
from pathlib import Path
|
|||
|
|
|
|||
|
|
# 工作目录
|
|||
|
|
workspace = Path(__file__).parent
|
|||
|
|
|
|||
|
|
|
|||
|
|
def start_server():
|
|||
|
|
"""启动服务器进程(在新的控制台窗口)"""
|
|||
|
|
print("=" * 60)
|
|||
|
|
print("正在启动 QTrade Server(新窗口)...")
|
|||
|
|
print("=" * 60)
|
|||
|
|
subprocess.Popen(
|
|||
|
|
[sys.executable, "-m", "src.networks.server.ws_server"],
|
|||
|
|
cwd=workspace,
|
|||
|
|
creationflags=subprocess.CREATE_NEW_CONSOLE, # Windows下在新控制台窗口启动
|
|||
|
|
)
|
|||
|
|
print("✓ 服务器已在新窗口启动,等待5秒...")
|
|||
|
|
|
|||
|
|
|
|||
|
|
def start_client():
|
|||
|
|
"""启动客户端进程(直接显示输出)"""
|
|||
|
|
print("\n" + "=" * 60)
|
|||
|
|
print("正在启动 Backtest Client...")
|
|||
|
|
print("=" * 60)
|
|||
|
|
subprocess.run([sys.executable, "-m", "src.backtest.main"], cwd=workspace)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
"""主函数"""
|
|||
|
|
if len(sys.argv) > 1 and sys.argv[1] == "server":
|
|||
|
|
# 只启动服务器
|
|||
|
|
start_server()
|
|||
|
|
elif len(sys.argv) > 1 and sys.argv[1] == "client":
|
|||
|
|
# 只启动客户端
|
|||
|
|
start_client()
|
|||
|
|
elif len(sys.argv) > 1 and sys.argv[1] == "both":
|
|||
|
|
# 同时启动服务器和客户端
|
|||
|
|
print("=" * 60)
|
|||
|
|
print("同时启动服务器和客户端")
|
|||
|
|
print("=" * 60)
|
|||
|
|
start_server()
|
|||
|
|
time.sleep(5) # 等待服务器启动
|
|||
|
|
print("\n现在启动客户端...")
|
|||
|
|
start_client()
|
|||
|
|
else:
|
|||
|
|
print("使用方法:")
|
|||
|
|
print(" 启动服务器: python test_run.py server")
|
|||
|
|
print(" 启动客户端: python test_run.py client")
|
|||
|
|
print(" 同时启动: python test_run.py both")
|
|||
|
|
print("\n建议:")
|
|||
|
|
print(" 1. 先运行: python test_run.py server (会弹出新窗口)")
|
|||
|
|
print(" 2. 然后运行: python test_run.py client")
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
main()
|