Commit 7d6b784f authored by Dmitry Trofimov's avatar Dmitry Trofimov

Test disabling of tracing returning None from trace function

parent 17e63f6a
......@@ -49,7 +49,7 @@ cdef int trace_trampoline(PyObject* _traceobj, PyFrameObject* _frame, int what,
if result is None:
PyEval_SetTrace(NULL, None)
return -1
return 0
else:
return 0
......@@ -87,6 +87,16 @@ def _create__failing_line_trace_func(trace):
return _trace_func
return _trace_func
def _create_disable_tracing(trace):
func = _create_trace_func(trace)
def _trace_func(frame, event, arg):
if frame.f_lineno - frame.f_code.co_firstlineno == 2:
return None
func(frame, event, arg)
return _trace_func
return _trace_func
def cy_add(a,b):
x = a + b # 1
......@@ -198,3 +208,24 @@ def fail_on_line_trace(fail_func):
else:
assert x == 5
return trace
def disable_trace(func, *args):
"""
>>> def py_add(a,b):
... x = a+b
... return x
>>> disable_trace(py_add, 1, 2)
[('call', 0), ('line', 1)]
>>> disable_trace(cy_add, 1, 2)
[('call', 0), ('line', 1)]
>>> disable_trace(cy_add_with_nogil, 1, 2)
[('call', 0), ('line', 1)]
"""
trace = []
PyEval_SetTrace(<Py_tracefunc>trace_trampoline, _create_disable_tracing(trace))
try:
func(*args)
finally:
PyEval_SetTrace(NULL, None)
return trace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment