【发布时间】:2012-04-19 21:53:21
【问题描述】:
如何在Google App Engine运行时python27下profilepython代码?
在运行时 python 是由这段代码完成的 - python runtime:
from google.appengine.ext import webapp
class PageHandler(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, WebApp World!')
def real_main():
application = webapp.WSGIApplication([('/', PageHandler)], debug=True)
run_wsgi_app(application)
def profile_main():
# This is the main function for profiling
# We've renamed our original main() above to real_main()
import cProfile, pstats, StringIO
prof = cProfile.Profile()
prof = prof.runctx('real_main()', globals(), locals())
stream = StringIO.StringIO()
stats = pstats.Stats(prof, stream=stream)
stats.sort_stats('cumulative')
logging.info("Profile data:\n%s", stream.getvalue())
if __name__ == "__main__":
profile_main()
在运行时 python27 必须以不同的方式完成,因为没有主调用 - 如何做同样的事情 - 我想切换到 python27 但不是没有分析。如何在 python27 中附加分析器 - python27 runtime?
import webapp2
class PageHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, WebApp World!')
app = webapp2.WSGIApplication([('/', PageHandler)])
【问题讨论】:
-
You can still specify CGI script handlers in app.yaml.如果我理解正确,如果您不需要concurrent requests,您仍然可以使用旧方法@ -
可能是 app.yaml 的使用不好,因为想在没有 cgi 的情况下进行测试,而不是每次测试都编辑 app.yaml(它很慢)。
标签: python google-app-engine profile python-2.7