Created
March 6, 2014 18:08
-
-
Save cameronmaske/9395840 to your computer and use it in GitHub Desktop.
Really useful for debugging functions, particularly in django's manage.py shell
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
import sys | |
def tracer(frame, event, arg): | |
if event != 'call': | |
return | |
co = frame.f_code | |
func_name = co.co_name | |
if func_name == 'write': | |
# Ignore write() calls from print statements | |
return | |
func_line_no = frame.f_lineno | |
func_filename = co.co_filename | |
caller = frame.f_back | |
caller_line_no = caller.f_lineno | |
caller_filename = caller.f_code.co_filename | |
print 'Call to %s on line %s of %s from line %s of %s' % (func_name, func_line_no, func_filename, caller_line_no, caller_filename) | |
return | |
sys.setprofile(tracer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment