pyppin.threading.stack_trace_internals¶
The actual meat of stack tracing.
This file contains the “advanced” API which most users won’t need, as well as the implementation details; it lets you do things like examine and programmatically manipulate the threads of all stacks. Most users can stick to pyppin.threading.stack_trace instead.
Warning
The non-public methods in this library are non-public for a reason; they are subtle and quick to anger. Do not mess with them unless you understand Python’s GC system quite well.
Functions
|
Return the stack summaries for all active threads. |
|
Format a list of stacks neatly for printing. |
|
Print a collection of thread stacks. |
|
Print a list of trace lines. |
Classes
|
A ThreadStack represents a single thread and its stack info. |
|
One logical "line" of the stack trace, including a trailing newline. |
|
The different kinds of line in a trace that may require different visual representation. |
- class pyppin.threading.stack_trace_internals.TraceLineType(value)[source]¶
Bases:
Enum
The different kinds of line in a trace that may require different visual representation.
- class pyppin.threading.stack_trace_internals.TraceLine(line: str, line_type: TraceLineType)[source]¶
Bases:
NamedTuple
One logical “line” of the stack trace, including a trailing newline.
It’s only a logical line; this may also include internal newlines.
- line_type: TraceLineType[source]¶
How the line should be rendered.
- classmethod as_trace(lines: Iterable[str], line_type: TraceLineType = TraceLineType.TRACE_LINE, prefix: str = '') Iterator[TraceLine] [source]¶
Convert a sequence of lines of text to a sequence of
TraceLines
.
- class pyppin.threading.stack_trace_internals.ThreadStack(thread: Optional[Thread], stack: Optional[StackSummary], exception: Optional[BaseException])[source]¶
Bases:
object
A ThreadStack represents a single thread and its stack info.
You generally acquire these objects with functions like all_stacks, below.
NB that self.exception is going to be a TracebackException object, not the original exception, in order to avoid all sorts of exciting reference counting cycles and other things that can make your life unpleasant. Net is that it’s safe to keep one of these objects around, you don’t need to do magical “dear-gods-delete-this-quickly” magic like with frame objects.
- property native_thread_id: Optional[int][source]¶
The native thread ID of this thread, if it’s started.
- property formatted: List[TraceLine][source]¶
This thread’s stack, formatted as a list of TraceLines.
- property cluster_id: int[source]¶
A “similarity identifier” for this thread’s stack trace.
If two threads have the same cluster ID, then their stack traces are effectively identical and (if grouping is turned on) should be merged in rendering.
This is especially useful if you have a bunch of “listener” or “worker” threads in your program which may be doing the same thing; it greatly simplifies the stack trace without losing data.
- pyppin.threading.stack_trace_internals.all_stacks(limit: Optional[int] = None, daemons: bool = True) List[ThreadStack] [source]¶
Return the stack summaries for all active threads.
- Parameters
limit – If given, this is the maximum number of stack trace entries to return for each thread. (This is the same meaning as the argument of the same name used in the traceback module)
daemons – If True, include daemon threads.
- Returns
All the active threads, in no particular order.
- pyppin.threading.stack_trace_internals.format_stacks(stacks: List[ThreadStack], group: bool = True) List[TraceLine] [source]¶
Format a list of stacks neatly for printing.
- Parameters
stacks – The stacks to format.
group – If True, group together threads with identical traces.
- pyppin.threading.stack_trace_internals.print_trace(lines: List[TraceLine], output: Optional[TextIOBase] = None) None [source]¶
Print a list of trace lines.
- Parameters
lines – The lines to print.
output – Where to write them to, defaulting to stderr.
- pyppin.threading.stack_trace_internals.print_stacks(stacks: List[ThreadStack], output: Optional[TextIOBase] = None, group: bool = True) None [source]¶
Print a collection of thread stacks.
- Parameters
stacks – The stacks to print.
output – Where to write them to, defaulting to stderr.
group – If True, group together threads with identical traces.