Skip to content

Commit b7430fa

Browse files
committed
debug: more convenient run_trace.py
1 parent e2039d0 commit b7430fa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lab/run_trace.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ def trace(frame, event, arg):
1414
# This can happen when Python is shutting down.
1515
return None
1616

17-
print("%s%s %s %d @%d" % (
18-
" " * nest,
19-
event,
20-
os.path.basename(frame.f_code.co_filename),
21-
frame.f_lineno,
22-
frame.f_lasti,
23-
))
17+
if the_program in frame.f_code.co_filename:
18+
print("%s%s %s %d @%d" % (
19+
" " * nest,
20+
event,
21+
os.path.basename(frame.f_code.co_filename),
22+
frame.f_lineno,
23+
frame.f_lasti,
24+
))
2425

2526
if event == 'call':
2627
nest += 1
@@ -33,5 +34,6 @@ def trace(frame, event, arg):
3334
the_program = sys.argv[1]
3435

3536
code = open(the_program, encoding="utf-8").read()
37+
code_obj = compile(code, the_program, mode="exec")
3638
sys.settrace(trace)
37-
exec(code)
39+
exec(code_obj)

0 commit comments

Comments
 (0)