|
43 | 43 |
|
44 | 44 | logger = logging.getLogger('pipe_worker') |
45 | 45 |
|
| 46 | +_diagnostics_logged = False |
| 47 | + |
| 48 | + |
| 49 | +def _log_node_diagnostics() -> None: |
| 50 | + """Dump hostname, PBS/Slurm array context, PATH, PYTHONPATH, TMPDIR, and |
| 51 | + group membership on first task failure. A dead compute node otherwise |
| 52 | + leaves no trace of *which* node it was — the PBS `.e` file records the |
| 53 | + array index but not the hostname, and ``tracejob`` is admin-only on |
| 54 | + many sites. Logging once per worker process keeps the volume bounded |
| 55 | + when one bad node drains many tasks. |
| 56 | + """ |
| 57 | + global _diagnostics_logged |
| 58 | + if _diagnostics_logged: |
| 59 | + return |
| 60 | + _diagnostics_logged = True |
| 61 | + import socket |
| 62 | + import subprocess |
| 63 | + try: |
| 64 | + host = socket.gethostname() |
| 65 | + except Exception: |
| 66 | + host = 'unknown' |
| 67 | + logger.error('--- NODE DIAGNOSTICS (first task failure on this worker) ---') |
| 68 | + logger.error(f'hostname={host}') |
| 69 | + for k in ('PBS_JOBID', 'PBS_ARRAY_INDEX', 'PBS_O_WORKDIR', |
| 70 | + 'SLURM_JOB_ID', 'SLURM_ARRAY_TASK_ID', 'SLURM_NODELIST'): |
| 71 | + v = os.environ.get(k) |
| 72 | + if v is not None: |
| 73 | + logger.error(f'{k}={v}') |
| 74 | + logger.error(f'PATH={os.environ.get("PATH", "")}') |
| 75 | + logger.error(f'PYTHONPATH={os.environ.get("PYTHONPATH", "")}') |
| 76 | + logger.error(f'TMPDIR={os.environ.get("TMPDIR", "")}') |
| 77 | + try: |
| 78 | + id_out = subprocess.run(['id'], capture_output=True, text=True, timeout=5).stdout.strip() |
| 79 | + logger.error(f'id={id_out}') |
| 80 | + except Exception as exc: |
| 81 | + logger.error(f'id=<failed: {exc}>') |
| 82 | + logger.error('--- END NODE DIAGNOSTICS ---') |
| 83 | + |
46 | 84 |
|
47 | 85 | def setup_logging(log_path: str) -> None: |
48 | 86 | """Configure logging. Safe to call multiple times.""" |
@@ -202,6 +240,7 @@ def run_task(pipe_root: str, task_id: str, state: TaskStateRecord, |
202 | 240 | failure_class = type(e).__name__ |
203 | 241 | ended_at = time.time() |
204 | 242 | logger.error(f'Task {task_id} failed: {failure_class}: {e}') |
| 243 | + _log_node_diagnostics() |
205 | 244 | if scratch_dir: |
206 | 245 | _copy_outputs(scratch_dir, attempt_dir) |
207 | 246 | result = locals().get('result') or _make_result_template(task_id, state.attempt_index, started_at) |
|
0 commit comments