Execute outdated notebooks in parallel, capped at EXEC_JOBS workers. jupyter-cache's parallel pool sizes itself from os.cpu_count() with no CLI knob, so we run jcache in a shim that patches cpu_count — keeping load sane on small machines.
(force=False)
| 184 | |
| 185 | |
| 186 | def jcache_execute(force=False): |
| 187 | """Execute outdated notebooks in parallel, capped at EXEC_JOBS workers. |
| 188 | |
| 189 | jupyter-cache's parallel pool sizes itself from os.cpu_count() with no CLI |
| 190 | knob, so we run jcache in a shim that patches cpu_count — keeping load sane |
| 191 | on small machines. |
| 192 | """ |
| 193 | shim = ( |
| 194 | f"import os; os.cpu_count = lambda: {int(EXEC_JOBS)}; " |
| 195 | "from jupyter_cache.cli.commands.cmd_main import jcache; jcache()" |
| 196 | ) |
| 197 | cmd = [sys.executable, "-c", shim, "project", "execute", |
| 198 | "--executor", "local-parallel", "--timeout", EXEC_TIMEOUT] |
| 199 | if force: |
| 200 | cmd.append("--force") |
| 201 | print(f"⚡ Executing {'ALL' if force else 'outdated'} notebooks " |
| 202 | f"({EXEC_JOBS} parallel, {EXEC_TIMEOUT}s/cell timeout)...") |
| 203 | result = subprocess.run(cmd, input="y\n", text=True, check=False) |
| 204 | if result.returncode != 0: |
| 205 | sys.exit(result.returncode) |
| 206 | return result |
| 207 | |
| 208 | |
| 209 | def clean_docs(): |