bpo-29400: sys.settracestate. by gwk · Pull Request #3236 · python/cpython (original) (raw)
This patch adds a new pair of functions to sys: settracestate
and gettracestate
. The old settrace
/gettrace
pair are now equivalent to calling settracestate
with trace_instructions=False
; when set to True
, the tracer callback is called for every bytecode instruction. This is useful for observing and instrumenting bytecode, e.g. for intraline code coverage. gettracestate
returns a dictionary that completely represents the tracing state. The old gettrace
now raises an exception if trace_instructions=True
, because it is no longer capturing the complete state. This guards against subtle failure for existing code that uses the old = gettrace(); ... ; settrace(old)
idiom.