Some changes were made to the interpreter:
sys.settrace(func)
sets the global trace function
Trace functions have three arguments: frame, event, and
arg. frame is the current stack frame. event is a
string: 'call'
, 'line'
, 'return'
, 'exception'
,
'c_call'
, 'c_return'
, or 'c_exception'
. arg
depends on the event type.
The global trace function is invoked (with event set to
'call'
) whenever a new local scope is entered; it should return
a reference to the local trace function to be used that scope, or
None
if the scope shouldn't be traced.
The local trace function should return a reference to itself (or to
another function for further tracing in that scope), or None
to
turn off tracing in that scope.
Instance methods are accepted (and very useful!) as trace functions.
The events have the following meaning:
'call'
None
;
the return value specifies the local trace function.
'line'
None
; the return value specifies the new
local trace function.
'return'
'exception'
(exception, value,
traceback)
; the return value specifies the new local trace
function.
'c_call'
'c_return'
None
.
'c_exception'
None
.
Note that as an exception is propagated down the chain of callers, an
'exception'
event is generated at each level.
For more information on code and frame objects, refer to the Python Reference Manual.
See About this document... for information on suggesting changes.