Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,20 @@ def g(frame, event, arg):
finally:
sys.settrace(existing)

def test_line_event_raises_before_opcode_event(self):
exception = ValueError("BOOM!")
def trace(frame, event, arg):
if event == "line":
raise exception
frame.f_trace_opcodes = True
return trace
def f():
pass
with self.assertRaises(ValueError) as caught:
sys.settrace(trace)
f()
self.assertIs(caught.exception, exception)


# 'Jump' tests: assigning to frame.f_lineno within a trace function
# moves the execution position - it's how debuggers implement a Jump
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a possible assertion failure, fatal error, or :exc:`SystemError` if a
line tracing event raises an exception while opcode tracing is enabled.
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -6933,7 +6933,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
}
}
/* Always emit an opcode event if we're tracing all opcodes. */
if (f->f_trace_opcodes) {
if (f->f_trace_opcodes && result == 0) {
result = call_trace(func, obj, tstate, frame, PyTrace_OPCODE, Py_None);
}
return result;
Expand Down