Browse files

More explanatory comments about hack for identifying threads on the d…

…ev server for the sampling profiler
  • Loading branch information...
1 parent ae58f07 commit 40f48e15410c3fb52f5062d0f4e947d2484bb30f @kamens kamens committed Jan 5, 2013
Showing with 10 additions and 0 deletions.
  1. +10 −0
@@ -124,6 +124,16 @@ def take_sample(self):
# properly. threading.current_thread().ident always returns -1
# in dev. So instead, we just take a peek at the stack's
# current package to figure out if it is the request thread.
+ # Even though the dev server is single-threaded,
+ # sys._current_frames will return multiple threads, because
+ # some of them are spawned by the App Engine dev server for
+ # internal purposes. We don't want to sample these internal dev
+ # server threads -- we want to sample the thread that is
+ # running the current request. Since the dev server will be
+ # running this sampling code immediately from the run() code
+ # below, we can spot this thread's stack by looking at its
+ # global namespace (f_globals) and making sure it's currently
+ # in the gae_mini_profiler package.
should_sample = (stack.f_globals["__package__"] ==

0 comments on commit 40f48e1

Please sign in to comment.