MCPcopy Create free account
hub / github.com/bloomberg/pystack / format_thread

Function format_thread

src/pystack/traceback_formatter.py:66–90  ·  view source on GitHub ↗
(thread: PyThread, native_mode: NativeReportingMode)

Source from the content-addressed store, hash-verified

64
65
66def format_thread(thread: PyThread, native_mode: NativeReportingMode) -> Iterable[str]:
67 native = native_mode != NativeReportingMode.OFF
68 current_frame: Optional[PyFrame] = thread.first_frame
69 if current_frame is None and not native:
70 yield f"The frame stack for thread {thread.tid} is empty"
71 return
72
73 thread_name = f" ({thread.name}) " if thread.name else " "
74 yield (
75 f"Traceback for thread {thread.tid}{thread_name}{thread.status} "
76 "(most recent call last):"
77 )
78
79 if not (native and _are_the_stacks_mergeable(thread)):
80 if native:
81 yield "* - Unable to merge native stack due to insufficient native information - *"
82 while current_frame is not None:
83 if not current_frame.is_shim:
84 yield from format_frame(current_frame)
85 current_frame = current_frame.next
86 else:
87 yield from _format_merged_stacks(
88 thread, current_frame, native_mode == NativeReportingMode.LAST
89 )
90 yield ""
91
92
93def _format_merged_stacks(

Calls 3

format_frameFunction · 0.85
_format_merged_stacksFunction · 0.85