Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49522

settrace doesn't trace builtin functions

Newsgroups comp.lang.python
Date 2013-06-30 19:11 -0700
Message-ID <694830e3-080c-4e66-90e2-6cbab53be071@googlegroups.com> (permalink)
Subject settrace doesn't trace builtin functions
From skunkwerk <skunkwerk@gmail.com>

Show all headers | View raw


Hi,
  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:

def wrapped_open(*arg,**kw):
	print 'open called'
	traceback.print_stack()
	f = __builtin__.open(*arg,**kw)
	return f
open = wrapped_open

but that seemed very brittle to me.

Could someone suggest a better way of doing this?

thank you,
imran

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

settrace doesn't trace builtin functions skunkwerk <skunkwerk@gmail.com> - 2013-06-30 19:11 -0700
  Re: settrace doesn't trace builtin functions Skip Montanaro <skip@pobox.com> - 2013-07-01 04:32 -0500

csiph-web