python - debug wrapper for external functions -
i looking way simultaneously print , execute function/method in similar wrapping function. issue can not directly decorate function function calling part of jython module. have along lines
from jythonmodule import fun, obj fun(a,b,c) o = obj o.method(e,f)
i looking away run , print code show
fun(a,b,c) o.method(e,f)
and execute commands. how without having access jython module? cheers
you can use sys.settrace
:
# trace.py import sys def trace_function(frame, event, arg): if event == "call": # report function calls code_name = frame.f_code.co_name code = frame.f_code print "function call: {0} @ {1}:{2}".format(code.co_name, code.co_filename, code.co_firstlineno) print "locals:", frame.f_locals print return trace_function # continue tracing new scope def f0(arg): print "in f0: ", arg print "done" def f1(arg): print "in f1: ", arg f0(arg) def f2(arg): print "in f2: ", arg f1(arg) sys.settrace(trace_function) f2("the arg string")
will give following output:
$ python trace.py: function call: f2 @ trace.py:23 locals: {'arg': 'the arg string'} in f2: arg string function call: f1 @ trace.py:19 locals: {'arg': 'the arg string'} in f1: arg string function call: f0 @ trace.py:15 locals: {'arg': 'the arg string'} in f0: arg string done function call: _remove @ /users/thomas/.virtualenvs/ec2vpn/lib/python2.7/_weakrefset.py:38 locals: {'item': <weakref @ 0x106743158; dead>, 'selfref': <weakref @ 0x1067956d8; 'weakset' @ 0x1067949d0>} function call: _remove @ /users/thomas/.virtualenvs/ec2vpn/lib/python2.7/_weakrefset.py:38 locals: {'item': <weakref @ 0x1067430a8; dead>, 'selfref': <weakref @ 0x106743050; 'weakset' @ 0x106744e90>}
Comments
Post a Comment