From 45c99b41b34381577912ee1708dcff8d25ae1759 Mon Sep 17 00:00:00 2001 From: dmy Date: Wed, 7 Jan 2026 01:40:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=20native=20=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E7=9A=84=20run.io=5Fbound()=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 native=True 模式下不能使用 run.io_bound() 执行 CPU 密集型任务 - 将 PowerShell 调用改为同步执行 subprocess.run() - 解决 'Unable to run CPU-bound in script mode' 错误 --- gui.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/gui.py b/gui.py index c9f3fea..1ff03ef 100644 --- a/gui.py +++ b/gui.py @@ -399,18 +399,14 @@ def index(): print("DEBUG: invoking PowerShell SaveFileDialog...") - # 使用 run.io_bound 在线程中执行,避免阻塞 UI - def run_ps(): - result = subprocess.run( - ["powershell", "-Command", ps_script], - capture_output=True, - text=True, - startupinfo=startupinfo - ) - return result.stdout.strip() - - from nicegui import run - save_path = await run.io_bound(run_ps) + # 在 native 模式下直接同步执行,不使用 run.io_bound() + result = subprocess.run( + ["powershell", "-Command", ps_script], + capture_output=True, + text=True, + startupinfo=startupinfo + ) + save_path = result.stdout.strip() if save_path: print(f"DEBUG: PowerShell returned path: {save_path}")