This commit is contained in:
parent
80d8543f2a
commit
1d1cc7eb09
15
gradio_ui.py
15
gradio_ui.py
|
|
@ -4,6 +4,7 @@ import glob
|
|||
import threading
|
||||
import subprocess
|
||||
import gradio as gr
|
||||
import psutil
|
||||
|
||||
# ---------------- 全局进程句柄 ----------------
|
||||
current_process = None
|
||||
|
|
@ -96,12 +97,22 @@ def run_eval(
|
|||
def stop_eval():
|
||||
global current_process
|
||||
if current_process and current_process.poll() is None:
|
||||
current_process.terminate()
|
||||
current_process = None
|
||||
try:
|
||||
# 使用 psutil 杀死所有子进程
|
||||
parent = psutil.Process(current_process.pid)
|
||||
children = parent.children(recursive=True)
|
||||
for child in children:
|
||||
child.kill()
|
||||
parent.kill()
|
||||
except Exception as e:
|
||||
return f"[Error stopping process] {e}\n"
|
||||
finally:
|
||||
current_process = None
|
||||
return "[Stopped by user]\n"
|
||||
return "[No active process]\n"
|
||||
|
||||
|
||||
|
||||
# ---------------- Run/Stop 控制器 ----------------
|
||||
def toggle_run(
|
||||
inputs, native, other, output_choices,
|
||||
|
|
|
|||
Loading…
Reference in New Issue