The document discusses debugging in Python 3.6. It describes tracing and frame evaluation debuggers. Tracing debuggers slow code execution significantly by calling the tracing function on every line. Python 3.6 introduced a new frame evaluation API that allows evaluating frames directly, avoiding the performance issues of tracing. The document demonstrates how to build a debugger using this approach, including setting breakpoints and stepping through code by inserting temporary breakpoints on each line. Frame evaluation allows building a debugger that is faster than tracing debuggers without significant performance penalties.
Report
Share
Report
Share
1 of 96
Download to read offline
More Related Content
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
11. 1
2
3
4
5
6
7
8
9
1 call
2 line
def foo():
friends = ["Bob", "Tom"]
for f in friends:
print("Hi %s!” % f)
return len(friends)
sys.settrace(tracefunc)
foo()
Tracing Function
11
12. 1
2
3
4
5
6
7
8
9
1 call
2 line
3 line
4 line
Hi Bob!
def foo():
friends = ["Bob", "Tom"]
for f in friends:
print("Hi %s!” % f)
return len(friends)
sys.settrace(tracefunc)
foo()
Tracing Function
12
13. 1
2
3
4
5
6
7
8
9
1 call
2 line
3 line
4 line
Hi Bob!
3 line
4 line
Hi Tom!
def foo():
friends = ["Bob", "Tom"]
for f in friends:
print("Hi %s!” % f)
return len(friends)
sys.settrace(tracefunc)
foo()
Tracing Function
13
14. 1
2
3
4
5
6
7
8
9
1 call
2 line
3 line
4 line
Hi Bob!
3 line
4 line
Hi Tom!
5 line
5 return
def foo():
friends = ["Bob", "Tom"]
for f in friends:
print("Hi %s!” % f)
return len(friends)
sys.settrace(tracefunc)
foo()
Tracing Function
14
16. Tracing Debugger
• Suspend program if breakpoint’s
line equals frame.f_lineno
• Handle events for stepping
16
17. Performance
def foo():
friends = ["Bob", "Tom"]
for f in friends:
print("Hi %s!” % f)
return len(friends)
sys.settrace(tracefunc)
foo()
1
2
3
4
5
6
7
8
9
1 call
2 line
3 line
4 line
Hi Bob!
3 line
4 line
Hi Tom!
5 line
5 return
17
19. Example 1
def calculate():
sum = 0
for i in range(10 ** 7):
sum += i
return sum
def tracefunc(frame, event, arg):
return tracefunc
1
2
3
4
5
6
7
8
9
19