fd5787c55f
- .mcp.json - bash/functions/infra/write_mcp_jupyter_config.md - bash/functions/infra/write_mcp_jupyter_config.sh - cpp/CMakeLists.txt - cpp/apps/chart_demo - cpp/apps/shaders_lab - cpp/functions/gfx/gl_framebuffer.cpp - cpp/functions/gfx/gl_framebuffer.h - cpp/functions/gfx/gl_framebuffer.md - cpp/functions/gfx/mesh_gpu.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4.2 KiB
4.2 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| jupyter_run_cells | function | py | notebook | 1.0.0 | impure | jupyter_run_cells(notebook_path: str, cell_indices: list[int], server_url: str, token: str, stop_on_error: bool, timeout_per_cell_s: int) -> dict | Ejecuta un lote de celdas existentes (por indice) en una sola conexion WebSocket. Un GET inicial + un PUT final. Latencia fija ~3s en vez de ~3s * N de jupyter_execute_cell individual. |
|
|
false | error_go_core |
|
|
Dict con notebook, executed (lista de resultados por celda), stopped_at, kernel_id y total_duration_s | true |
|
python/functions/notebook/tests/test_jupyter_run_cells.py | python/functions/notebook/jupyter_run_cells.py |
Ejemplo
from notebook.jupyter_run_cells import jupyter_run_cells
result = jupyter_run_cells(
notebook_path="notebooks/analisis.ipynb",
cell_indices=[0, 1, 2, 5],
server_url="http://localhost:8888",
token="",
stop_on_error=True,
)
# {
# "notebook": "notebooks/analisis.ipynb",
# "executed": [
# {"cell_index": 0, "execution_count": 1, "outputs": ["import ok"], "error": None, "duration_s": 1.2},
# {"cell_index": 1, "execution_count": 2, "outputs": ["42"], "error": None, "duration_s": 0.1},
# ...
# ],
# "stopped_at": None,
# "kernel_id": "abc-123",
# "total_duration_s": 4.8,
# }
CLI:
# Indices como argumentos posicionales
python python/functions/notebook/jupyter_run_cells.py notebooks/analisis.ipynb 0 1 2 5
# Indices via stdin JSON (util desde scripts)
echo '[0, 1, 2, 5]' | python python/functions/notebook/jupyter_run_cells.py notebooks/analisis.ipynb
# No parar en error + timeout custom
python python/functions/notebook/jupyter_run_cells.py notebooks/analisis.ipynb 0 1 2 \
--no-stop-on-error --timeout 120
Cuando usarla
Cuando necesites re-ejecutar varias celdas de un notebook existente y el overhead de abrir/cerrar N conexiones WS sea inaceptable (>3 celdas, celdas pesadas, o en pipelines automatizados). Sustituye a llamar jupyter_execute_cell N veces en bucle desde el agente.
Gotchas
- Las celdas deben existir previamente en el notebook. Para anadir y ejecutar celdas nuevas, usar
jupyter_append_executedejupyter_exec. - Solo ejecuta celdas de tipo
code. Pasar el indice de una celda markdown lanzaValueErrorantes de abrir el WS. - El
PUTfinal se hace siempre, incluso sistop_on_errordetiene el lote. El notebook queda con los outputs de las celdas ejecutadas hasta el punto de parada. KernelClientignoratimeout_per_cell_ssi la implementacion subyacente no lo soporta (depende de la version dejupyter-kernel-client). En ese caso el timeout global del proceso es el unico limite.- Si el servidor Jupyter no esta corriendo,
_ensure_sessionlanzaURLErrorinmediatamente (no hay retry incorporado). - El WS se abre con el
kernel_idde la sesion activa del notebook. Si el kernel muere entre el_ensure_sessiony la ejecucion,KernelClientlanzara una excepcion.