Skip to content

Instantly share code, notes, and snippets.

@kaidokert
Last active April 29, 2018 19:39
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 kaidokert/28837f8bc9c181fe28f2e8bcf0dcdde1 to your computer and use it in GitHub Desktop.
Save kaidokert/28837f8bc9c181fe28f2e8bcf0dcdde1 to your computer and use it in GitHub Desktop.
Tracing excessive callers to re.compile in re.py
callers = {}
def _ghetto_compile(pattern, flags=0):
import inspect
try:
frame = '{}'.format(inspect.currentframe().f_back.f_code)
val = callers.setdefault(frame,0)
callers[frame] = val + 1
# print(frame)
if 'rest_framework.py' in frame:
pass
#print(sorted(callers.iteritems(),key=lambda (k,v):(v,k),reverse=True))
except Exception as e:
print('fail {}'.format(e) )
"Compile a regular expression pattern, returning a pattern object."
return _compile(pattern, flags)
def compile(pattern, flags=0):
"Compile a regular expression pattern, returning a pattern object."
return _compile(pattern, flags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment