Python 3.12+Linuxsysfunction
sys.activate_stack_trampoline()
debugging and tracing
Enables trampolines for the perf profiler so its report shows Python function names. Linux only; the only backend is 'perf'.
Syntax
sys.activate_stack_trampoline('perf')
It is for people profiling Python with the system perf tool on Linux; it is useless for cProfile or ordinary debugging. While active, the interpreter writes /tmp/perf-<PID>.map and runs a bit slower. Running python -X perf gives the same effect without code changes. It cannot be activated while the JIT is on, and an unknown backend name raises ValueError. Windows and macOS lack it entirely.
Examples
import sys
if sys.platform == 'linux':
try:
sys.activate_stack_trampoline('nope')
except ValueError as e:
print(e) # → invalid backend: nope
print(sys.is_stack_trampoline_active()) # → False
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy