Skip to content
Merged
Changes from 7 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
18 changes: 12 additions & 6 deletions python/tvm_ffi/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,25 @@ def append_traceback(
The new traceback with the appended frame.

"""
frame = self._create_frame(filename, lineno, func)
return types.TracebackType(tb, frame, frame.f_lasti, lineno)
# Magic hack to prevent a circular reference
Comment thread
KEKE046 marked this conversation as resolved.
Outdated
Comment thread
KEKE046 marked this conversation as resolved.
Outdated
def create(tb: types.TracebackType | None, frame: types.FrameType, lineno: int) -> types.TracebackType:
Comment thread
KEKE046 marked this conversation as resolved.
Outdated
return types.TracebackType(tb, frame, frame.f_lasti, lineno)
return create(tb, self._create_frame(filename, lineno, func), lineno)


_TRACEBACK_MANAGER = TracebackManager()


def _with_append_backtrace(py_error: BaseException, backtrace: str) -> BaseException:
"""Append the backtrace to the py_error and return it."""
tb = py_error.__traceback__
for filename, lineno, func in _parse_backtrace(backtrace):
tb = _TRACEBACK_MANAGER.append_traceback(tb, filename, lineno, func)
return py_error.with_traceback(tb)
# we manually delete py_error and tb to avoid reference cycle, making it faster to gc the locals inside the frame
Comment thread
KEKE046 marked this conversation as resolved.
Outdated
try:
tb = py_error.__traceback__
for filename, lineno, func in _parse_backtrace(backtrace):
tb = _TRACEBACK_MANAGER.append_traceback(tb, filename, lineno, func)
return py_error.with_traceback(tb)
finally:
del py_error, tb
Comment thread
KEKE046 marked this conversation as resolved.


def _traceback_to_backtrace_str(tb: types.TracebackType | None) -> str:
Expand Down
Loading