Back to Labs
Python runtime

Python runtime explorer

Step through Python execution to see frames, scopes, bytecode, and objects. Edit the code and run it again to see how the runtime changes.

Python editor

Run the trace to capture frames, scopes, and bytecode.

Loading Python runtime
First load can take a moment while the runtime downloads.
Scenario
Closures and nonlocal

Watch how a nested function holds on to a cell variable.

Playback

Play through the trace or step one event at a time.

Trace not loaded
Max steps
Run the trace to build a step timeline.

Source view

1
def make_counter():
2
count = 0
3
def step():
4
nonlocal count
5
count = count + 1
6
return count
7
return step
8
9
counter = make_counter()
10
values = []
11
for i in range(3):
12
values.append(counter())
13
14
class Box:
15
def __init__(self, value):
16
self.value = value
17
18
box = Box(values)
19
total = sum(values)
20
print("values", values)
21
print("total", total)
22
print("box", box.value)
23

Call stack

Run the trace to see frames.

Scopes

Run the trace to see frame data.

Scope resolution

Run the trace to see scope lookup.

Value stack

Run the trace to see stack data.

Bytecode

Run the trace to see bytecode.

Variable changes

Run the trace to see changes.