fix: 移除 native 模式下的 run.io_bound() 调用

- 在 native=True 模式下不能使用 run.io_bound() 执行 CPU 密集型任务
- 将 PowerShell 调用改为同步执行 subprocess.run()
- 解决 'Unable to run CPU-bound in script mode' 错误
This commit is contained in:
dmy
2026-01-07 01:40:42 +08:00
parent 837158270e
commit 45c99b41b3

20
gui.py
View File

@@ -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}")