python's sys.settrace won't trace builtin functions -
this question has answer here:
i've been using sys.settrace function write tracer program, working great except doesn't seem called built-in functions, open('filename.txt'). behavior doesn't seem documented, i'm not sure if i'm doing wrong or if expected behavior. using doug hellmann's "trace_calls_and_returns" code here tracing function.
if can't settrace, there way trace calls open()? don't want use linux's strace, it'll run whole program (not part want trace) , won't show python line numbers/file names, etc. other option considered monkey-patching open function through wrapper, like:
import traceback, __builtin__ def wrapped_open(*arg,**kw): print 'open called' traceback.print_stack() f = __builtin__.open(*arg,**kw) return f open = wrapped_open
but seemed brittle me.
could suggest better way of doing this?
you won't able trace compiled code imported python, , open()
not pure python, it's c binding cpython part of python distribution.
so way you'll have trace within open()
go strace
or equivalent, in ways, beyond python can introspect of himself.
Comments
Post a Comment