fix(compute): 修复进度条跳变(20%→100%)

原因:外部引擎 stdout 管道缓存,Python 每 0.2s 读一行,
引擎结束时管道中大量库存进度消息没被用于更新进度条。

修复:
1. 子进程退出时扫描残留 stdout 中的 progress 消息并更新 pbar
2. sleep 从 0.2s 降到 0.05s,提高读取频率
This commit is contained in:
2026-06-11 22:48:34 +08:00
parent db50ac6d4d
commit 52505e9aff
+7 -1
View File
@@ -775,8 +775,14 @@ def run_engine(engine, input_dir, output_dir, config):
_r = _r.strip() _r = _r.strip()
if _r: if _r:
_engine_lines.append(_r) _engine_lines.append(_r)
# 读取残留在管道中的进度消息,避免 20%→100% 跳变
_prog_match = re.search(r'progress:\s*(\d+)/(\d+)', _r)
if _pbar is not None and _prog_match:
_p_done = min(int(_prog_match.group(1)), total_steps)
_pbar.n = max(_pbar.n, _p_done)
if _pbar is not None: _pbar.refresh()
break break
time.sleep(0.2) time.sleep(0.05)
finally: finally:
if _pbar is not None: if _pbar is not None:
_pbar.n = total_steps _pbar.n = total_steps