python - Return value while using cProfile -


I'm trying an example method profile, so I did something like this:

  import cProfile class test (def): def __init __ (self): pass def method (self): cProfile.runctx ("self.method_actual ()", globals (), local () def method_actual (self): Print "run" if __name__ == "__main__": test (). Method ()  

But now problems arise when I want "method" to return the value calculated by "method_actual". I really do not want to call "method_actual" twice.

Is there any other way, which can be some thread safe? (In my application, CRPlise data is saved in data files in the name of one of the algms, so they do not stick and I can add them later.)

I found out that you can:

  prof = cprofile.profile () retval = prof.runcall (self. Method_actual, * args, ** kwargs) prof.dump_stats (datafn)  

The downside is that it is undocumented.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -