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


Groups > comp.lang.python > #49522

settrace doesn't trace builtin functions

X-Received by 10.224.86.200 with SMTP id t8mr24207906qal.0.1372644715722; Sun, 30 Jun 2013 19:11:55 -0700 (PDT)
X-Received by 10.50.40.65 with SMTP id v1mr683462igk.4.1372644715676; Sun, 30 Jun 2013 19:11:55 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!j2no1889691qak.0!news-out.google.com!f7ni121qai.0!nntp.google.com!j2no3121568qak.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Sun, 30 Jun 2013 19:11:55 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=108.233.254.238; posting-account=WlGYkAoAAADVhKf_1Nhh8RSlYLt0v1vA
NNTP-Posting-Host 108.233.254.238
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <694830e3-080c-4e66-90e2-6cbab53be071@googlegroups.com> (permalink)
Subject settrace doesn't trace builtin functions
From skunkwerk <skunkwerk@gmail.com>
Injection-Date Mon, 01 Jul 2013 02:11:55 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:49522

Show key headers only | 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