Skip to content

Variables and the debugger

igaurab edited this page Nov 18, 2026 · 2 revisions

The variables panel shows the names that your cells defined. When a cell is paused, the same panel becomes the debugger.

Variables

Open the panel with ctrl+v in cell mode, or with :vars. The panel is in the right column. When the outline is also open, the outline is above it.

Each row shows:

  • The name.
  • The type.
  • The shape, length or dtype, for example (3, 4) float64 or len 12.
  • A short value.
  • The cell that set the name.

Go to the panel with ctrl+w l. Then use these keys:

Key Action
j / k Move
enter Show the full value: text, or a table for a DataFrame or 2-D data. The size has a limit
g Go to the line of the cell that set the variable
d Delete the variable from the kernel. The cell that set it becomes stale
/ Filter by name or type
a Hide or show modules, functions and classes. They show by default
q Hide the panel
escape Go back to the notebook. The panel stays
ctrl+w h / j / k Go to the notebook / to the outline below or above

The debugger

Start the debugger

How Result
Put breakpoint() in a cell and run it The cell pauses on that line
r d or :debug on a cell The cell runs and pauses on its first line
r d or :debug on a cell whose last run failed The debugger opens on the line that raised the error (post-mortem)

When a cell is paused, the badge shows DEBUG and the paused line is lit in its cell. While no cell is paused, gpython installs nothing in the kernel. Thus a normal run has no added cost.

What the panel shows

Item How it shows
Loops for i in range(n) i=3 4/10 ████░░, with nested loops below
Lists, tuples, strings, 1-D arrays A strip of boxes, with an arrow for each index that the code uses
Index out of range The arrow is after the strip, in red, with a warning
2-D lists and arrays A grid, with the [i][j] cell lit
Dicts and sets Added, removed and changed keys
Locals What changed since the last stop, and the earlier values (total: 0 → 1 → 4)

Example: the code nums[j + 1] gives an arrow with the label j + 1.

Keys

Step

Key Action
n Next line
s Step into a call
r Run until the function returns
c Continue
q Stop the debugger. The cell stops

Loops

Key Action
] Next iteration of the inner loop
} Next iteration of the outer loop
) Run to the end of the inner loop
G Go to iteration N of the inner loop. N L uses loop level L (1 is the outer loop)

Stop on a condition

Key Action
b Run until an expression is true. gpython records nothing on the way, so it is fast
B The same, but gpython records each line
:stop if EXPR The same as b, as a command

Example expressions: j == len(nums) - 1, loss != loss.

Time travel

Key Action
h / l Go back / forward through the recorded steps
T Timeline: one row for each iteration. l / h open and close inner loops. enter goes to a row

The timeline shows changed values and a ⚠ where an index was out of range.

Examine

Key Action
u / d Up / down the stack
w Add a watch expression
e Type a pdb command (p expr, pp, !stmt)
enter Show the full value of the local at the cursor
g Go to the paused line in its cell
a Hide or show modules, functions and classes
/ Filter the locals

r i also stops a paused cell. r k restarts the kernel.

pdb breakpoints

Press e, then type b 12 to set a pdb breakpoint on line 12. gpython underlines the line in the cell. The keys ], }, ) and b also stop at these breakpoints.

Library code

When you step into library code with s, gpython records these steps too. They show as file.py:12 in f().

How much is recorded

The debugger records each step so that you can go back in time. One setting controls the quantity: debug_detail.

Set it with :set debug_detail=.... gpython saves it. It applies to the next recording.

Value What gpython keeps Size limit
full (default) Each step with each value 200 MB
auto Same as full until 10,000 steps, then same as balanced —
balanced Changes only, with a full copy each 100 steps. Old iterations become thinner 20 MB
lean Only the loop positions and the watched names 5 MB

How balanced makes old iterations thinner: it keeps each line of the last three iterations, one moment for each older iteration, then each 10th and each 100th.

The footer of the panel shows the status, for example full · 1,240 steps · 3.1 MB / 200 MB. With auto, the footer shows auto → balanced after the change.

Limits that you can set one by one

Each key replaces one limit of the selected debug_detail value.

Key Meaning full balanced lean
debug_history Maximum memory, for example 20MB or 1GB 200 MB 20 MB 5 MB
debug_events Maximum number of recorded steps 2,000,000 200,000 50,000
debug_thinning on or off: make old iterations thinner off on aggressive
debug_repr_chars Maximum characters of a value 2000 80 40
debug_strip_items Maximum items in a strip 500 40 20
debug_grid_size Maximum rows and columns in a grid 50 20 10
debug_stats watched, cpu or off: statistics for arrays watched watched watched
  • debug_stats=cpu adds statistics for small arrays that are on the CPU.
  • :set debug_history? shows the value in effect and where it comes from. This works for each debug_ key.

Tensors and arrays

For all values of debug_detail:

  • gpython shows tensors and arrays by type, shape, dtype and device. This applies in lists too.
  • gpython does not synchronize with the GPU.
  • The strips show the pointers but no values.
  • Watched tensors and arrays also show their values, mean, min, max and the NaN count.

Clone this wiki locally