Skip to content

Running cells

igaurab edited this page Nov 18, 2026 · 3 revisions

gpython tracks which variables each cell defines and uses, and runs follow that graph.

Run modes

Running a cell first runs the stale cells it depends on (never run, edited since, or their inputs changed), then the cell. What happens to the cells below it, the ones that use its variables, is the run mode (f3, saved):

  • lazy (the default): they are only marked stale. You run what you want, when you want, without moving: r 6 runs cell c6, r c this cell, r r the cell you ran last, r C the cells down to this one, r a the cells after it, r A all, r s the stale ones (f4); r k restarts the kernel, r R restarts and runs all, r i interrupts; r t 5 times this cell over five runs and prints a bordered table under it (mean, median, std, variance, p50 / p90 / p99, min, max), like %%timeit (r t alone runs it once; :timeit 5). The same keys work in the editor's normal mode, where space r … is a synonym.
  • reactive: they re-run automatically, like marimo.

Concurrent cells

Turn on with :set concurrent, off by default, saved: cells of a run that share no state run at the same time, on threads in the one kernel. A cell may join others only if neither writes anything the other reads or writes (Bernstein's conditions); gpython works this out from the code, counting as a write every assignment, in-place change (xs.append, d[k] = v, a function that changes a global), call it does not know, and effect such as writing a file, seeding random or drawing with plt. Magics, top-level await, input() and breakpoint() run alone. Each cell's output, errors and r i still work per cell. :groups (or gpy --groups nb.py) shows the groups and what each cell waits for; :set concurrency=N caps how many run at once (1 runs them one by one). After a group, the names its cells shared are checked: if one changed anyway, its readers are marked stale and run one by one from then on (:set noconcurrent_verify turns the check off). Network calls, sleeps and NumPy run in parallel; pure-Python loops take turns (the GIL); cells that write files run one at a time. While a group runs, NumPy's math libraries are held to their share of the cores with threadpoolctl (a gpython dependency); a kernel in a project .venv or conda env needs it installed there too, or parallel NumPy cells may oversubscribe the cores.

Rules (same as marimo)

  • A name may be defined in only one cell. Repeating the identical import (import seaborn as sns in two cells) is allowed; the first cell owns the name.
  • Names starting with _ are private to their cell.
  • In-place changes (xs.append(1), d["k"] = v) at a cell's top level are tracked: readers below run after the mutator, and running the mutator first re-runs the cell that created the object so it starts fresh.

Clone this wiki locally