fix(compute): 校准测速使用真实临时目录替代 os.devnull
os.devnull 在 Windows 上为 NUL,外部引擎(C/C++/Fortran) 试图写入 NUL/trajectory.txt 会失败退出,导致校准时间 完全无效,进度条按错误估计跑(例如卡在 59% 不动)。 改为创建 _calib_out 临时目录,校准后清理。 现在进度条显示正确的剩余时间估计(如 [00:00<00:11])。
This commit is contained in:
+9
-1
@@ -719,10 +719,18 @@ def run_engine(engine, input_dir, output_dir, config):
|
|||||||
_calib_path = os.path.join(script_dir, "engines", engine, "_calib.json")
|
_calib_path = os.path.join(script_dir, "engines", engine, "_calib.json")
|
||||||
with open(_calib_path, "w", encoding="utf-8") as _cf:
|
with open(_calib_path, "w", encoding="utf-8") as _cf:
|
||||||
json.dump(_calib_param, _cf, indent=2)
|
json.dump(_calib_param, _cf, indent=2)
|
||||||
|
_calib_outdir = os.path.join(script_dir, "engines", engine, "_calib_out")
|
||||||
|
os.makedirs(_calib_outdir, exist_ok=True)
|
||||||
_ct0 = time.time()
|
_ct0 = time.time()
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[engine_path, os.path.abspath(input_dir), os.devnull, _calib_path],
|
[engine_path, os.path.abspath(input_dir), _calib_outdir, _calib_path],
|
||||||
capture_output=True, timeout=60)
|
capture_output=True, timeout=60)
|
||||||
|
# 清理校准临时文件
|
||||||
|
for _f in os.listdir(_calib_outdir):
|
||||||
|
try: os.remove(os.path.join(_calib_outdir, _f))
|
||||||
|
except OSError: pass
|
||||||
|
try: os.rmdir(_calib_outdir)
|
||||||
|
except OSError: pass
|
||||||
os.remove(_calib_path)
|
os.remove(_calib_path)
|
||||||
_calib_elapsed = max(time.time() - _ct0, 0.001)
|
_calib_elapsed = max(time.time() - _ct0, 0.001)
|
||||||
_overhead = _calib_elapsed * 0.15
|
_overhead = _calib_elapsed * 0.15
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user