A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
more debug logging in kernel (#2097)
Akshay Agrawald4d41e191b1f
diff --git a/marimo/_runtime/complete.py b/marimo/_runtime/complete.pyindex 1d06598c7d..afc53a82d2 100644--- a/marimo/_runtime/complete.py+++ b/marimo/_runtime/complete.py@@ -279,6 +279,7 @@ def _get_completions_with_interpreter(completions = []locked = glbls_lock.acquire(blocking=False)if locked:+ LOGGER.debug("Completion worker acquired globals lock")completions = script.complete()return script, completions@@ -437,6 +438,8 @@ def complete(except Exception:# RLock raises if released when not acquired.pass+ else:+ LOGGER.debug("Completion worker released globals lock.")def completion_worker(diff --git a/marimo/_runtime/dataflow.py b/marimo/_runtime/dataflow.pyindex 375c5b3144..3529b7cbfa 100644--- a/marimo/_runtime/dataflow.py+++ b/marimo/_runtime/dataflow.py@@ -105,7 +105,9 @@ class DirectedGraph:Requires that `cell_id` is not already in the graph."""+ LOGGER.debug("Acquiring graph lock to register cell %s", cell_id)with self.lock:+ LOGGER.debug("Acquired graph lock.")assert cell_id not in self.cellsself.cells[cell_id] = cell# Children are the set of cells that refer to a name defined in@@ -163,7 +165,7 @@ class DirectedGraph:if path:self.cycles.add(tuple([(other_id, cell_id)] + path))self.children[other_id].add(cell_id)-+ LOGGER.debug("Registered cell %s and released graph lock", cell_id)if self.is_any_ancestor_stale(cell_id):self.set_stale(set([cell_id]))@@ -225,7 +227,9 @@ class DirectedGraph:Returns the ids of the children of the removed cell."""+ LOGGER.debug("Acquiring graph lock to delete cell %s", cell_id)with self.lock:+ LOGGER.debug("Acquired graph lock to delete cell %s", cell_id)if cell_id not in self.cells:raise ValueError(f"Cell {cell_id} not found")@@ -265,8 +269,8 @@ class DirectedGraph:for elems in self.siblings.values():if cell_id in elems:elems.remove(cell_id)-- return children+ LOGGER.debug("Deleted cell %s and Released graph lock.", cell_id)+ return childrendef is_disabled(self, cell_id: CellId_t) -> bool:if cell_id not in self.cells:diff --git a/marimo/_runtime/reload/module_watcher.py b/marimo/_runtime/reload/module_watcher.pyindex 403eafcb64..030874298e 100644--- a/marimo/_runtime/reload/module_watcher.py+++ b/marimo/_runtime/reload/module_watcher.py@@ -8,6 +8,7 @@ import threadingimport timefrom typing import TYPE_CHECKING, Callable, Literal+from marimo import _loggersfrom marimo._messaging.types import Streamfrom marimo._runtime import dataflowfrom marimo._runtime.reload.autoreload import (@@ -20,6 +21,8 @@ if TYPE_CHECKING:from marimo._ast.cell import CellId_t+LOGGER = _loggers.marimo_logger()+def is_submodule(src_name: str, target_name: str) -> bool:"""Returns True if src_name is a parent of target_name@@ -132,12 +135,15 @@ def watch_modules(# Collect the modules used by each cellmodules: dict[str, types.ModuleType] = {}modname_to_cell_id: dict[str, CellId_t] = {}+ LOGGER.debug("Acquiring graph lock to find imported modules.")with graph.lock:+ LOGGER.debug("Acquired graph lock.")for cell_id, cell in graph.cells.items():for modname in modules_imported_by_cell(cell, sys_modules):if modname in sys_modules:modules[modname] = sys_modules[modname]modname_to_cell_id[modname] = cell_id+ LOGGER.debug("Released graph lock and found imported modules.")stale_modules = _check_modules(modules=modules,@@ -146,7 +152,11 @@ def watch_modules()if stale_modules:+ LOGGER.debug(+ "Found stale modules; acquiring lock to update graph."+ )with graph.lock:+ LOGGER.debug("Acquired graph lock.")for modname in stale_modules.keys():# prune definitions that are derived from stale modulescell = graph.cells[modname_to_cell_id[modname]]@@ -170,6 +180,8 @@ def watch_modules()for cid in stale_cell_ids:graph.cells[cid].set_stale(stale=True, stream=stream)+ LOGGER.debug("Released graph lock and updated stale statuses.")+if mode == "autorun":run_is_processed.clear()enqueue_run_stale_cells()diff --git a/marimo/_runtime/runner/cell_runner.py b/marimo/_runtime/runner/cell_runner.pyindex 755c0d7118..19b8bdedd6 100644--- a/marimo/_runtime/runner/cell_runner.py+++ b/marimo/_runtime/runner/cell_runner.py@@ -518,11 +518,13 @@ class Runner:return ref, blamed_cellasync def run_all(self) -> None:+ LOGGER.debug("Running preparation hooks")for prep_hook in self.preparation_hooks:prep_hook(self)while self.pending():cell_id = self.pop_cell()+ LOGGER.debug("Cell runner processing %s", cell_id)cell = self.graph.cells[cell_id]# Update run result status for cells that won't run.@@ -530,28 +532,35 @@ class Runner:# Hack: frontend sets status to queued on run, so we also have to# set runtime_state to get FE to transition.if self.cancelled(cell_id):+ LOGGER.debug("%s cancelled", cell_id)cell.set_run_result_status("cancelled")cell.set_runtime_state("idle")continueif cell.config.disabled:+ LOGGER.debug("%s disabled", cell_id)cell.set_run_result_status("disabled")cell.set_runtime_state("idle")continueif self.graph.is_disabled(cell_id):+ LOGGER.debug("%s disabled transitively", cell_id)cell.set_run_result_status("disabled")cell.set_runtime_state("disabled-transitively")continue+ LOGGER.debug("Running pre_execution hooks")for pre_hook in self.pre_execution_hooks:pre_hook(cell, self)+ LOGGER.debug("Running cell %s", cell_id)if self.execution_context is not None:with self.execution_context(cell_id) as exc_ctx:run_result = await self.run(cell_id)run_result.accumulated_output = exc_ctx.outputelse:run_result = await self.run(cell_id)+ LOGGER.debug("Running post_execution hooks")for post_hook in self.post_execution_hooks:post_hook(cell, self, run_result)+ LOGGER.debug("Running on_finish hooks")for finish_hook in self.on_finish_hooks:finish_hook(self)diff --git a/marimo/_runtime/runner/hooks_post_execution.py b/marimo/_runtime/runner/hooks_post_execution.pyindex b2d7d5992f..197eea1484 100644--- a/marimo/_runtime/runner/hooks_post_execution.py+++ b/marimo/_runtime/runner/hooks_post_execution.py@@ -46,7 +46,9 @@ def _set_imported_defs(run_result: cell_runner.RunResult,) -> None:del run_result+ LOGGER.debug("Acquiring graph lock to update cell import workspace")with runner.graph.lock:+ LOGGER.debug("Acquired graph lock to update import workspace.")if cell.import_workspace.is_import_block:cell.import_workspace.imported_defs = set(name for name in cell.defs if name in runner.glbls@@ -115,6 +117,7 @@ def _broadcast_datasets(])if tables:+ LOGGER.debug("Broadcasting data tables")Datasets(tables=tables).broadcast()@@ -143,6 +146,7 @@ def _broadcast_duckdb_tables(if not tables:return+ LOGGER.debug("Broadcasting duckdb tables")Datasets(tables=tables, clear_channel="duckdb").broadcast()except Exception:returndiff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex f8a70c6921..fe2eed491c 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -787,6 +787,7 @@ class Kernel:Returns- set of cells that must be run to return kernel to consistent state"""+ LOGGER.debug("Mutating graph.")LOGGER.debug("Current set of errors: %s", self.errors)cells_before_mutation = set(self.graph.cells.keys())cells_with_errors_before_mutation = set(self.errors.keys())@@ -1491,6 +1492,7 @@ class Kernel:debug(error_title, error_message)else:found = True+ LOGGER.debug("Executing RPC %s", request)with self._install_execution_context(cell_id=function.cell_id), ctx.provide_ui_ids(str(uuid4())):@@ -1668,7 +1670,9 @@ class Kernel:"""# acquiring and releasing an RLock takes ~100ns; the overhead is# negligible because the lock is coarse.+ LOGGER.debug("Acquiring globals lock to handle request %s", request)with self.lock_globals():+ LOGGER.debug("Handling control request: %s", request)if isinstance(request, CreationRequest):await self.instantiate(request)CompletedRun().broadcast()@@ -1690,6 +1694,7 @@ class Kernel:CompletedRun().broadcast()elif isinstance(request, FunctionCallRequest):status, ret, _ = await self.function_call_request(request)+ LOGGER.debug("Function returned with status %s", status)FunctionCallResult(function_call_id=request.function_call_id,return_value=ret,@@ -1707,6 +1712,7 @@ class Kernel:return Noneelse:raise ValueError(f"Unknown request {request}")+ LOGGER.debug("Handled control request: %s", request)def launch_kernel(@@ -1844,7 +1850,7 @@ def launch_kernel(# triggered on Windows when quit with Ctrl+CLOGGER.debug("kernel queue.get() failed %s", e)break- LOGGER.debug("received request %s", request)+ LOGGER.debug("Received control request: %s", request)if isinstance(request, StopRequest):breakelif isinstance(request, SetUIElementValueRequest):