all Python 3sysfunction
sys.getprofile()
debugging and tracing
Returns the profiling function set with sys.setprofile(), or None — for example, to swap it temporarily and restore it later.
Syntax
sys.getprofile()
The profiler and the tracer are two separate slots: getprofile() does not see what settrace() installed, and vice versa. Since Python 3.12 cProfile runs on sys.monitoring, so under it getprofile() returns None — the slot shows only what sys.setprofile() installed. Save the old value before installing yours and restore it in finally, or you will switch off someone else's profiler.
Examples
import sys
def prof(frame, event, arg):
pass
old = sys.getprofile()
print(old) # → None
sys.setprofile(prof)
try:
print(sys.getprofile() is prof) # → True
finally:
sys.setprofile(old)
print(sys.getprofile()) # → None
See also
Open in the full glossarydocs.python.orgReport an inaccuracy