Spaces:
Paused
Paused
lanny xu
commited on
Commit
·
9285882
1
Parent(s):
febcb81
optimize query speed
Browse files- run_server.py +19 -2
run_server.py
CHANGED
|
@@ -152,8 +152,25 @@ if __name__ == "__main__":
|
|
| 152 |
server_thread.daemon = True
|
| 153 |
server_thread.start()
|
| 154 |
|
| 155 |
-
# 等待服务器启动
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
use_tunnel = os.environ.get("USE_TUNNEL", "true").lower() == "true"
|
| 159 |
if use_tunnel:
|
|
|
|
| 152 |
server_thread.daemon = True
|
| 153 |
server_thread.start()
|
| 154 |
|
| 155 |
+
# 等待服务器启动 (循环检查端口)
|
| 156 |
+
print("⏳ 等待服务器启动...")
|
| 157 |
+
import socket
|
| 158 |
+
def wait_for_port(port, host='127.0.0.1', timeout=60):
|
| 159 |
+
start_time = time.time()
|
| 160 |
+
while True:
|
| 161 |
+
try:
|
| 162 |
+
with socket.create_connection((host, port), timeout=1):
|
| 163 |
+
print(f"✅ 服务器已在 {host}:{port} 就绪")
|
| 164 |
+
return True
|
| 165 |
+
except (OSError, ConnectionRefusedError):
|
| 166 |
+
if time.time() - start_time > timeout:
|
| 167 |
+
print(f"❌ 服务器启动超时 ({timeout}s)")
|
| 168 |
+
return False
|
| 169 |
+
time.sleep(1)
|
| 170 |
+
|
| 171 |
+
if not wait_for_port(8000):
|
| 172 |
+
print("❌ 服务器未能成功启动,请检查日志")
|
| 173 |
+
sys.exit(1)
|
| 174 |
|
| 175 |
use_tunnel = os.environ.get("USE_TUNNEL", "true").lower() == "true"
|
| 176 |
if use_tunnel:
|