Skip to content

Commit

Permalink
cutting trace size
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed Nov 26, 2023
1 parent 923009c commit 9204e3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion instld/cli/traceback_cutting/cutting.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import sys
import traceback

from instld.cli.traceback_cutting.traceback_utils import cut_base_of_traceback
from instld.cli.traceback_cutting.traceback_utils import cut_base_of_traceback, cut_importlib_bug


def create_cutting_excepthook(old_hook, base_size):
def new_hook(exc_type, value, traceback_object):
traceback_object = cut_base_of_traceback(traceback_object, base_size)
traceback_object = cut_importlib_bug(traceback_object)
traceback.print_exception(exc_type, value, traceback_object)
return new_hook

Expand Down
9 changes: 8 additions & 1 deletion instld/cli/traceback_cutting/traceback_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ def count_traceback_lenth(traceback_object):
def cut_base_of_traceback(traceback_object, base_size):
index = 0
while traceback_object is not None:
#print(traceback_object.tb_frame.f_code.co_qualname, dir(traceback_object.tb_frame.f_code.co_qualname))
#print(traceback_object.tb_frame.f_code.co_qualname, traceback_object.tb_frame.f_code.co_filename)
if index == base_size:
return traceback_object
index += 1
traceback_object = traceback_object.tb_next


def cut_importlib_bug(traceback_object):
while traceback_object is not None:
if not (traceback_object.tb_frame.f_code.co_qualname == '_call_with_frames_removed' and traceback_object.tb_frame.f_code.co_filename == '<frozen importlib._bootstrap>'):
return traceback_object
traceback_object = traceback_object.tb_next

0 comments on commit 9204e3f

Please sign in to comment.