function::thread_indent_depth - Linux
Overview
The thread_indent_depth
function returns the indentation depth of the current thread. The indentation depth is the number of spaces or tabs that are prepended to the beginning of each line of the thread’s stack trace.
This function can be used to determine the nesting level of a thread. For example, a thread that is running inside a function that is running inside another function will have a greater indentation depth than a thread that is running at the top level.
Syntax
thread_indent_depth() -> int
Options/Flags
None.
Examples
The following example shows how to use the thread_indent_depth
function to determine the nesting level of a thread:
import threading
def foo():
print("hello from foo")
print(threading.current_thread().indent_depth)
def bar():
print("hello from bar")
print(threading.current_thread().indent_depth)
t1 = threading.Thread(target=foo)
t1.start()
t2 = threading.Thread(target=bar)
t2.start()
Output:
hello from foo
1
hello from bar
2
Common Issues
None.
Integration
The thread_indent_depth
function can be used with other threading functions to gain insights into the behavior of a multithreaded program. For example, the function can be used to identify threads that are running at a deep nesting level, which may be a sign of a performance problem.
Related Commands
threading.current_thread()
threading.enumerate()