Python Glossary Русский

all Python 3sysfunction

sys.gettrace()

debugging and tracing

Returns the trace function set with sys.settrace(), or None. This is how a program can tell it runs under a debugger or coverage.

Syntax

sys.gettrace()

A non-None value almost always means an outside tool: an IDE debugger, pdb or a coverage run. Speed tests use it to know their numbers will be skewed. It sees only the current thread, and it does not reveal sys.monitoring (3.12+) or the profiler (sys.getprofile).

Examples

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

See also

Open in the full glossarydocs.python.orgReport an inaccuracy