Last active
October 9, 2017 15:51
-
-
Save hchasestevens/853416f01047211c4b02273c053ca4f2 to your computer and use it in GitHub Desktop.
Settrace recipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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