Profiling problem

Andrew M. Kuchling akuchlin at cnri.reston.va.us
Fri May 7 15:36:16 EDT 1999


Randall Hopper writes:
>Why does the following example fail to resolve "self"?

	Because the profile isn't being run with the right global and
local dictionaries.  Poke through profile.py and look at the run()
function, and follow the methods it calls.  The solution is to run
like this:

class C:
   def slow_dog( self ):
      import time
      time.sleep(5)
   def doit( self ):
      import profile
      prof = profile.Profile()
      prof.runctx( 'self.slow_dog()', globals(), locals() )
      prof.print_stats()
      
c = C()
c.doit()

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
Birds of a thousand colours danced in the sky when I was a boy. They
brightened the day with their intricate songs. "We are who we choose to be,"
sang the goldfinch, when the sun was high. "I dream about dreams about
dreams," sang the nightingale, under the pale moon.
    -- Master Li, in SANDMAN #74, "The Exile"





More information about the Python-list mailing list