diff --git a/ml/monitor.py b/ml/monitor.py index f03ee89..e8890b7 100644 --- a/ml/monitor.py +++ b/ml/monitor.py @@ -135,9 +135,14 @@ def stage_progress(st, s): """当前阶段的进度:返回 {'frac': 0..1 或 None(无法计量), 'label': 文字}。""" t0, info = s['start'], s.get('info') or {} if st == 'gen': - n = sum(LC.count(f) for f in newer(f'{DATA}/shard_*.jsonl', t0) + newer(f'{DATA}/shard_*.jsonl.part', t0)) + # 分子算全部(含之前轮次已完成的分片),分母是累计目标:补量时显示 50,008/79,688 而不是 0/79,688。 + # 2026-10-18 实测:只统计本轮开始后改过的文件会让"补量"看起来像从零开始。 + allf = glob.glob(os.path.join(ROOT, DATA, 'shard_*.jsonl')) + glob.glob(os.path.join(ROOT, DATA, 'shard_*.jsonl.part')) + n = sum(LC.count(f) for f in allf) tgt = info.get('target_tasks') or 0 - return {'frac': min(1, n / tgt) if tgt else None, 'label': f'已生成 {n:,} / {tgt:,} 条任务'} + new = sum(LC.count(f) for f in newer(f'{DATA}/shard_*.jsonl', t0) + newer(f'{DATA}/shard_*.jsonl.part', t0)) + lab = f'已生成 {n:,} / {tgt:,} 条任务' + (f'(本轮补 {new:,} 条)' if 0 < new < n else '') + return {'frac': min(1, n / tgt) if tgt else None, 'label': lab} if st == 'prep': nsh = len(glob.glob(os.path.join(ROOT, DATA, 'shard_*.jsonl'))) done = len(newer(f'{DATA}/samples/*.X.npy', t0)) @@ -347,6 +352,14 @@ class Job: with self.lock: if os.name == 'nt': subprocess.run(['taskkill', '/T', '/F', '/PID', str(pid)], capture_output=True) + # Git Bash 下 taskkill /T 只杀到 bash,node 孙进程会逃掉(2026-10-18 实测:点了停止还有 28 个 + # gen_dataset 在跑)。按命令行补扫:只动本仓库 ml/ 下的脚本,绝不碰用户自己的 node 进程。 + try: + q = ("Get-CimInstance Win32_Process -Filter \"Name='node.exe'\" | " + "Where-Object { $_.CommandLine -match 'gen_dataset\\.cjs|run_parallel\\.sh|teacher\\.cjs|policy_bench\\.cjs' } | " + "ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }") + subprocess.run(['pwsh', '-NoProfile', '-Command', q], capture_output=True, timeout=60) + except Exception: pass else: if ours: kill_session(pid)