def thread_details(io_handler, thread_id, max_depth=0):
        """
        Prints details about the thread with the given ID (not its name)
        """
        # Normalize maximum depth
        try:
            max_depth = int(max_depth)
            if max_depth < 1:
                max_depth = None
        except (ValueError, TypeError):
            max_depth = None

        # pylint: disable=W0212
        try:
            # Get the stack
            thread_id = int(thread_id)
            stack = sys._current_frames()[thread_id]
        except KeyError:
            io_handler.write_line("Unknown thread ID: {0}", thread_id)
        except ValueError:
            io_handler.write_line("Invalid thread ID: {0}", thread_id)
        except AttributeError:
            io_handler.write_line("sys._current_frames() is not available.")
        else:
            # Get the name
            try:
                name = threading._active[thread_id].name
            except KeyError:
                name = "<unknown>"

            lines = [
                "Thread ID: {0} - Name: {1}".format(thread_id, name),
                "Stack trace:",
            ]

            trace_lines = []
            depth = 0
            frame = stack
            while frame is not None and (
                max_depth is None or depth < max_depth
            ):
                # Store the line information
                trace_lines.append(format_frame_info(frame))

                # Previous frame...
                frame = frame.f_back
                depth += 1

            # Reverse the lines
            trace_lines.reverse()

            # Add them to the printed lines
            lines.extend(trace_lines)

            lines.append("")
            io_handler.write("\n".join(lines))
def thread_details ( io_handler , thread_id , max_depth = 0 ) : try : max_depth = int ( max_depth ) if max_depth < 1 : max_depth = None except ( ValueError , TypeError ) : max_depth = None try : thread_id = int ( thread_id ) stack = sys . _current_frames ( ) [ thread_id ] except KeyError : io_handler . write_line ( "Unknown thread ID: {0}" , thread_id ) except ValueError : io_handler . write_line ( "Invalid thread ID: {0}" , thread_id ) except AttributeError : io_handler . write_line ( "sys._current_frames() is not available." ) else : try : name = threading . _active [ thread_id ] . name except KeyError : name = "<unknown>" lines = [ "Thread ID: {0} - Name: {1}" . format ( thread_id , name ) , "Stack trace:" , ] trace_lines = [ ] depth = 0 frame = stack while frame is not None and ( max_depth is None or depth < max_depth ) : trace_lines . append ( format_frame_info ( frame ) ) frame = frame . f_back depth += 1 trace_lines . reverse ( ) lines . extend ( trace_lines ) lines . append ( "" ) io_handler . write ( "\n" . join ( lines ) )
Prints details about the thread with the given ID (not its name)