Python Glossary Русский

Python 3.10+threadingfunction

threading.gettrace()

tracing and profiling

Returns the trace function set with threading.settrace() for new threads, or None if there is none.

Syntax

threading.gettrace()

This is the value for future threads, not the current tracer: sys.gettrace() gives that, and in the main thread it may be None even when threading.gettrace() returns something. Debuggers and coverage install their own trace function, so a non-empty answer often means you are running under one. settrace_all_threads() changes this value as well.

Examples

import sys
import threading
print(threading.gettrace())  # → None
def tracer(frame, event, arg):
    return None
threading.settrace(tracer)
print(threading.gettrace() is tracer, sys.gettrace())  # → True None
threading.settrace(None)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy