FAQ

Peter Hansen wrote:
Sorry, I couldn't find a solution that was larger than six lines:
def trace(frame, event, arg):
... if event == 'line':
... print '%s: %s' % (frame.f_code.co_filename, frame.f_lineno)
... return trace
...
import sys
sys.settrace(trace)
-Peter
Hey,

This is exactly what I needed. Now, can you explain to me how I hook in a
"local" trace function to take over once I execute the function I'm
interested in tracing? I'd like to use the "event" argument to take note
of calls that are 1 level deep (ie in my foo function, any calls made) and
turn off tracing of these until they return back to the level of foo.

I presume I could implement this with a "if event == 'call':" condition, but
I can't seem to get a global trace function to hook up to a local trace
function ... it does one or two things right, then goes crazy.

Regards,
Mark

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 18 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedSep 19, '02 at 2:54a
activeSep 22, '02 at 11:51p
posts18
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase