This commit is contained in:
parent
3fb5def6d8
commit
1366a23a6b
12
gradio_ui.py
12
gradio_ui.py
|
|
@ -9,7 +9,7 @@ import signal
|
||||||
|
|
||||||
# ---------------- 全局进程句柄 ----------------
|
# ---------------- 全局进程句柄 ----------------
|
||||||
current_process = None
|
current_process = None
|
||||||
|
should_stop = False
|
||||||
|
|
||||||
# ---------------- 核心运行函数 ----------------
|
# ---------------- 核心运行函数 ----------------
|
||||||
def run_eval(
|
def run_eval(
|
||||||
|
|
@ -49,6 +49,8 @@ def run_eval(
|
||||||
)
|
)
|
||||||
|
|
||||||
for line in current_process.stdout:
|
for line in current_process.stdout:
|
||||||
|
if should_stop:
|
||||||
|
break
|
||||||
full_output += line
|
full_output += line
|
||||||
yield full_output, True, gr.update(value="Stop Evaluation")
|
yield full_output, True, gr.update(value="Stop Evaluation")
|
||||||
|
|
||||||
|
|
@ -96,10 +98,11 @@ def run_eval(
|
||||||
|
|
||||||
# ---------------- 停止函数 ----------------
|
# ---------------- 停止函数 ----------------
|
||||||
def stop_eval():
|
def stop_eval():
|
||||||
global current_process
|
global current_process, should_stop
|
||||||
|
should_stop = True
|
||||||
if current_process and current_process.poll() is None:
|
if current_process and current_process.poll() is None:
|
||||||
try:
|
try:
|
||||||
os.killpg(os.getpgid(current_process.pid), signal.SIGKILL) # ✅ 杀整个进程组
|
os.killpg(os.getpgid(current_process.pid), signal.SIGKILL)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"[Error stopping process group] {e}\n"
|
return f"[Error stopping process group] {e}\n"
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -109,6 +112,7 @@ def stop_eval():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------- Run/Stop 控制器 ----------------
|
# ---------------- Run/Stop 控制器 ----------------
|
||||||
def toggle_run(
|
def toggle_run(
|
||||||
inputs, native, other, output_choices,
|
inputs, native, other, output_choices,
|
||||||
|
|
@ -119,7 +123,9 @@ def toggle_run(
|
||||||
model_override,
|
model_override,
|
||||||
is_running
|
is_running
|
||||||
):
|
):
|
||||||
|
global should_stop # ✅ 加上这一行
|
||||||
if not is_running:
|
if not is_running:
|
||||||
|
should_stop = False
|
||||||
yield from run_eval(
|
yield from run_eval(
|
||||||
inputs, native, other, output_choices,
|
inputs, native, other, output_choices,
|
||||||
api_url, api_token,
|
api_url, api_token,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue