From b3d66c669c00e07f76e3fd1d8febaaaeb98ff919 Mon Sep 17 00:00:00 2001 From: yuruo Date: Tue, 4 Mar 2025 12:33:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=AD=89=E5=BE=85=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 905cdb9..ec4e24b 100644 --- a/main.py +++ b/main.py @@ -6,15 +6,27 @@ from gradio_ui import app from util import download_weights import time def run(): - # 启动 server.py 子进程 + # 启动 server.py 子进程,并捕获其输出 server_process = subprocess.Popen( ["python", "./server.py"], - creationflags=subprocess.CREATE_NEW_PROCESS_GROUP + stdout=subprocess.PIPE, # 捕获标准输出 + stderr=subprocess.PIPE, + creationflags=subprocess.CREATE_NEW_PROCESS_GROUP, + text=True ) + try: # 下载权重文件 download_weights.download() # 启动 Gradio UI + # 等待 server_process 打印出 "Started server process" + while True: + output = server_process.stdout.readline() + if "Started server process" in output: + print("Omniparseer服务启动成功...") + break + if server_process.poll() is not None: + raise RuntimeError("Server process terminated unexpectedly") app.run() finally: # 确保在主进程退出时终止子进程