Skip to content

Instantly share code, notes, and snippets.

@zhu327
Created July 27, 2018 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhu327/3749a3f6249b58f9c508714e75382608 to your computer and use it in GitHub Desktop.
Save zhu327/3749a3f6249b58f9c508714e75382608 to your computer and use it in GitHub Desktop.
Python调用栈跟踪
# coding: utf-8
from __future__ import print_function
import re
import sys
filter = re.compile(r'site-packages/requests/.*')
def tracer(frame, event, args):
if filter.search(frame.f_code.co_filename):
print({
'event': event,
'filename': frame.f_code.co_filename,
'lineno': frame.f_lineno,
'context': frame.f_code.co_name
})
return tracer
sys.settrace(tracer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment