As far as I know, every request has around 10-second runtime limitation. You may have seen this in your log:
<class 'google.appengine.runtime.DeadlineExceededError'>: Traceback (most recent call last): File "/base/data/home/apps/brps/1.330485825438182004/index.py", line 149, in <module> main() File "/base/data/home/apps/brps/1.330485825438182004/index.py", line 145, in main run_wsgi_app(application) File "/base/python_lib/versions/1/google/appengine/ext/webapp/util.py", line 76, in run_wsgi_app result = application(env, _start_response) [snip]
For sake of user experience, we need to deal with that. This post explains where you can import DeadlineExceededError.
# DeadlineExceededError can live in two different places try: # When deployed from google.appengine.runtime import DeadlineExceededError except ImportError: # In the development server from google.appengine.runtime.apiproxy_errors import DeadlineExceededError
By throwing in my app, the time is around 8.5 seconds. If you try to catch it, it does work, but what if you try to stall? (Yeah, you are a bad boy!)
class DeadlineExceededErrorPage(webapp.RequestHandler): def get(self): try: time.sleep(20) logging.debug('Impossible!') except DeadlineExceededError: logging.debug('Houston, we got a problem! But we are going to make it worse!') time.sleep(20) logging.debug('Houston, we really are in a big trouble!') logging.debug('We should never be here!') self.response.out.write('Done!')
I made this piece of code to try on production server (It didnt run as my expectation on development server, maybe I need to use urlfetch instead of sleep?), here is the log:
1.01-05 05:55AM 23.941 /DeadlineExceededError 500 9151ms 139ms-cpu 0kb 118.169.142.109 - - [05/Jan/2009:05:55:33 -0800] "GET /DeadlineExceededError HTTP/1.1" 500 0 - - 2.D 01-05 05:55AM 32.687 Houston, we got a problem! But we are going to make it worse! 3.E 01-05 05:55AM 33.090 <class 'google.appengine.runtime.DeadlineExceededError'>: Traceback (most recent call last): File "/base/data/home/apps/yjltest/1.330487966959697473/index.py", line 55, in main run_wsgi_app(application) File "/base/python_lib/versions/1/google/appengine/ext/webapp/util.py", line 76, in run_wsgi_app result = application(env, _start_response) File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 498, in __call__ handler.get(*groups) File "/base/data/home/apps/yjltest/1.330487966959697473/index.py", line 41, in get time.sleep(20)
Time to catch the exception is about 8.7 seconds, then at 9.1 seconds, we know the answer of the stalling, that is getting another DeadlineExceededError.
If you are really bad, you would ask why not try again? I tried, we dont have the second chance!