I've been using the settrace function to write a tracer for my program, which is working great except that it doesn't seem to work for built-in functions, like open('filename.txt'). This doesn't seem to be documented, so I'm not sure if I'm doing something wrong or that's the expected behavior.
If settrace's behavior in this regard is fixed, is there any way to trace calls to open()? I don't want to use Linux's strace, as it'll run for whole program (not just the part I want) and won't show my python line numbers/file names, etc. The other option I considered was monkey-patching the open function through a wrapper, like:
print 'open called'
f = __builtin__.open(*arg,**kw)
open = wrapped_open
but that seemed very brittle to me. Could someone suggest a better way of doing this?