Browse files

Search sys.meta_path for PathRestrictingImportHook

Summary: Fixes #71.

Test Plan: Added logging on line 23, saw it log successfully when using the mini profiler.

Reviewers: eliana

Reviewed By: eliana

CC: jlfwong

Differential Revision: http://phabricator.khanacademy.org/D7221
  • Loading branch information...
1 parent d810ee4 commit 0213ffb28a6d7f37880ba40b1c5ecd5c7af86681 @spicyj spicyj committed Mar 10, 2014
Showing with 10 additions and 3 deletions.
  1. +10 −3 linebyline_profiler.py
View
13 linebyline_profiler.py
@@ -17,9 +17,16 @@
# but we can monkey-patch it in here for use on the dev server:
if _is_dev_server:
if os.environ["SERVER_SOFTWARE"] == "Development/2.0":
- # module name looks something like 'gae_mini_profiler._line_profiler'
- sys.meta_path[3]._enabled_regexes.append(
- re.compile(r'(?:.*\.)?_line_profiler$'))
+ from google.appengine.tools.devappserver2.python import sandbox
+ for meta in sys.meta_path:
+ if isinstance(meta, sandbox.PathRestrictingImportHook):
+ # module name looks something like
+ # 'gae_mini_profiler._line_profiler'
+ meta._enabled_regexes.append(
+ re.compile(r'(?:.*\.)?_line_profiler$'))
+ break
+ else:
+ assert False, "Can't find PathRestrictingImportHook in meta_path"
else:
from google.appengine.tools import dev_appserver
if isinstance(sys.meta_path[0], dev_appserver.HardenedModulesHook):

0 comments on commit 0213ffb

Please sign in to comment.