注册器未启动时,整个启动链因为异常被终止
使用await asyncio.sleep(3)可以让后续代码等待一段时间,但不是最优解
This commit is contained in:
parent
3391155077
commit
d7c884e34a
18
startup.py
18
startup.py
|
|
@ -1,6 +1,7 @@
|
|||
from multiprocessing import Process, Queue
|
||||
import multiprocessing as mp
|
||||
import subprocess
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
from pprint import pprint
|
||||
|
|
@ -8,6 +9,7 @@ from pprint import pprint
|
|||
# 设置numexpr最大线程数,默认为CPU核心数
|
||||
try:
|
||||
import numexpr
|
||||
|
||||
n_cores = numexpr.utils.detect_number_of_cores()
|
||||
os.environ["NUMEXPR_MAX_THREADS"] = str(n_cores)
|
||||
except:
|
||||
|
|
@ -208,7 +210,7 @@ def _set_app_seq(app: FastAPI, q: Queue, run_seq: int):
|
|||
q.put(run_seq)
|
||||
|
||||
|
||||
def run_controller(q: Queue, run_seq: int = 1, log_level: str ="INFO"):
|
||||
def run_controller(q: Queue, run_seq: int = 1, log_level: str = "INFO"):
|
||||
import uvicorn
|
||||
import httpx
|
||||
from fastapi import Body
|
||||
|
|
@ -294,7 +296,7 @@ def run_model_worker(
|
|||
controller_address: str = "",
|
||||
q: Queue = None,
|
||||
run_seq: int = 2,
|
||||
log_level: str ="INFO",
|
||||
log_level: str = "INFO",
|
||||
):
|
||||
import uvicorn
|
||||
from fastapi import Body
|
||||
|
|
@ -497,15 +499,15 @@ def dump_server_info(after_start=False, args=None):
|
|||
print("\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
async def start_main_server():
|
||||
import time
|
||||
|
||||
mp.set_start_method("spawn")
|
||||
# TODO 链式启动的队列,确实可以用于控制启动顺序,
|
||||
# 但目前引入proxy_worker后,启动的独立于框架的work processes无法确认当前的位置,
|
||||
# 导致注册器未启动时,无法注册。整个启动链因为异常被终止
|
||||
# 需要将 `run_seq`设置为MAX_int,才能保证在最后启动。
|
||||
# 是否需要引入depends_on的机制?
|
||||
# 使用await asyncio.sleep(3)可以让后续代码等待一段时间,但不是最优解
|
||||
|
||||
queue = Queue()
|
||||
args, parser = parse_args()
|
||||
|
||||
|
|
@ -539,7 +541,7 @@ if __name__ == "__main__":
|
|||
processes = {"online-api": []}
|
||||
|
||||
def process_count():
|
||||
return len(processes) + len(processes["online-api"]) -1
|
||||
return len(processes) + len(processes["online-api"]) - 1
|
||||
|
||||
if args.quiet:
|
||||
log_level = "ERROR"
|
||||
|
|
@ -554,6 +556,7 @@ if __name__ == "__main__":
|
|||
daemon=True,
|
||||
)
|
||||
process.start()
|
||||
await asyncio.sleep(3)
|
||||
processes["controller"] = process
|
||||
|
||||
process = Process(
|
||||
|
|
@ -638,6 +641,9 @@ if __name__ == "__main__":
|
|||
process.terminate()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 同步调用协程代码
|
||||
asyncio.get_event_loop().run_until_complete(start_main_server())
|
||||
# 服务启动后接口调用示例:
|
||||
# import openai
|
||||
# openai.api_key = "EMPTY" # Not support yet
|
||||
|
|
|
|||
Loading…
Reference in New Issue