Skip to content

Commit 8676782

Browse files
larsgebclaude
andcommitted
Pages: pre-warm matplotlib font cache in parent before spawning subprocesses
The font cache build takes 30-60 s on a fresh CI runner inside `import matplotlib.pyplot as plt`. When this long initialization coincides with Metal GPU loading (_m1_gpu_ops) in the same process it causes SIGSEGV. Fix: run the matplotlib import and a dummy figure in the parent (orchestrator) process which never touches Metal. The cache is written to disk so every notebook subprocess finds it already built, making plt's import instant and eliminating the Metal ↔ matplotlib initialization overlap. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2e7c6d4 commit 8676782

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

scripts/render_notebooks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ def main() -> None:
160160
notebooks = [Path(p) for p in sys.argv[2:]]
161161
out_dir.mkdir(parents=True, exist_ok=True)
162162

163+
# ------------------------------------------------------------------
164+
# Pre-warm the matplotlib font cache.
165+
# Building the cache takes 30-60 s on a fresh CI runner and happens
166+
# inside `import matplotlib.pyplot as plt`. When this coincides with
167+
# Metal initialisation in the same subprocess the process can crash
168+
# (SIGSEGV). Running the import here — in the parent, which never
169+
# touches Metal — writes the cache to disk so that every notebook
170+
# subprocess finds it ready and skips the slow build entirely.
171+
# ------------------------------------------------------------------
172+
print("Pre-warming matplotlib font cache ...", flush=True)
173+
import matplotlib.pyplot as _plt # noqa: PLC0415
174+
_plt.figure()
175+
_plt.close("all")
176+
del _plt
177+
print(" font cache ready.", flush=True)
178+
163179
# ------------------------------------------------------------------
164180
# Phase 1 — execute each notebook in an isolated subprocess.
165181
# If the subprocess crashes (e.g. SIGSEGV / exit 139), we write a

0 commit comments

Comments
 (0)