Skip to content

Instantly share code, notes, and snippets.

@hchasestevens
Last active October 9, 2017 15:51
Show Gist options
  • Save hchasestevens/853416f01047211c4b02273c053ca4f2 to your computer and use it in GitHub Desktop.
Save hchasestevens/853416f01047211c4b02273c053ca4f2 to your computer and use it in GitHub Desktop.
Settrace recipe
def trace(frame, event, arg):
relevant_fname_substr = '' # populate with filename substring
try:
if relevant_fname_substr not in frame.f_code.co_filename:
return
print("{0.f_code.co_filename}: {0.f_lineno}".format(frame))
except Exception:
pass
from contextlib import contextmanager
@contextmanager
def tracing(trace_fn=trace):
import sys
sys.settrace(trace_fn)
try:
yield
finally:
sys.settrace(None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment