Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:45:15+00:00 2026-06-01T17:45:15+00:00

How to profile python code under Google App Engine runtime python27 ? In runtime

  • 0

How to profile python code under Google App Engine runtime python27?

In runtime python it was done by this code – 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()

In runtime python27 is has to be done differently since there is no main calls – how to do the same thing – I want to switch to python27 but not without profiling. How to attach profiler in 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)])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:45:17+00:00Added an answer on June 1, 2026 at 5:45 pm

    You can profile a WSGI app using WSGI middleware by inserting in your appengine_config.py:

    import cProfile
    import cStringIO
    import logging
    import pstats
    
    def webapp_add_wsgi_middleware(app):
    
      def profiling_wrapper(environ, start_response):
        profile = cProfile.Profile()
        response = profile.runcall(app, environ, start_response)
        stream = cStringIO.StringIO()
        stats = pstats.Stats(profile, stream=stream)
        stats.sort_stats('cumulative').print_stats()
        logging.info('Profile data:\n%s', stream.getvalue())
        return response
    
      return profiling_wrapper
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to profile python code from an object point of view. E.g.:
I am doing this through django $ python manage.py shell from django.contrib.auth.models import User
I'm trying to profile an instance method, so I've done something like: import cProfile
I am trying to profile twisted python code with Heapy . For example (pseudo
I want to profile my Python code. I am well-aware of cProfile , and
I'm currently using cProfile and pstats to profile some Python code. Is there a
Following script runs great: $ python myscript.py When I try to profile my code
I have the following code, which results in Python quitting unexpectedly: def profile_videos_sort_and_filter(profile, sort,
I've done some experiments using Apache Bench to profile my code response times, and
I was trying to learn how to profile a simple python program using hotshot,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.