Thanks for the response Marzia. I tried again with the return
statement and I am still having the same issue. The code I pasted
below is the entirety of my handler, so there is nothing in it that
would cause a timeout after the initial DeadlineExceededError. I also
checked that I am importing the correct DeadlineExceededError, and I
can tell the error is being caught because I get the "Ran out of
time." message in my logs. Any other ideas?
It is also interesting to note that for most exceptions I get a stack
trace of the error. In this case I am getting a Google branded page
titled "502 Server Error" that says:
Google Error
Server Error
The server encountered a temporary error and could not complete
your request.
Please try again in 30 seconds.
What is this page?
On Feb 23, 10:53 am, Marzia Niccolai <[email protected]> wrote:
> Hi Lenza,
>
> This works for me. So I think it might be one of two things.
>
> First, are you importing the correct DeadlineExceededError? You need to
> make sure to have this import:
> from google.appengine.runtime import DeadlineExceededError
>
> If you don't, sleeping for 30 seconds will raise this error, but it won't be
> caught.
>
> The other thing is that you need to explicitly return your handler after you
> print the error message or else the handler will keep executing, and that
> may be the cause of the error (not returning the message quick enough). So,
> modify the exception with:
> except DeadlineExceededError:
> logging.error("Ran out of time.")
> self.response.clear()
> self.response.set_status(500)
> self.response.out.write("This operation could not be completed in
> time...")
> return
>
> -Marzia
>
> On Sun, Feb 22, 2009 at 9:55 PM, lenza <[email protected]> wrote:
>
> > I am attempting to customize my application response to a
> > DeadlineExceededError. I am able to catch the exception, but my
> > custom response is not getting through. Instead I get the default
> > "502 Server Server Error" page even after clearing the response and
> > writing a custom one. It seems as if the GAE is allowing time for
> > cleanup, but ignoring anything written to the response object. Is
> > anyone doing this successfully?
>
> > More details...
>
> > The GAE documentation states that you can customize your applications
> > response to a DeadlineExceededError with the following example code
> > (seehttp://code.google.com/appengine/docs/python/runtime.html):
>
> > class MainPage(webapp.RequestHandler):
> > def get(self):
> > try:
> > # Do stuff...
>
> > except DeadlineExceededError:
> > self.response.clear()
> > self.response.set_status(500)
> > self.response.out.write("This operation could not be completed
> > in time...")
>
> > I have the following handler for "/test" on my App:
>
> > class TestPage(webapp.RequestHandle):
> > def get(self):
> > try:
> > sleeptime = int(self.request.get('sleep'))
> > if(sleeptime == 0):
> > logging.info("Programatically raising
> > DeadlineExceededError")
> > raise DeadlineExceededError
> > else:
> > time.sleep(sleeptime)
>
> > except DeadlineExceededError:
> > logging.error("Ran out of time.")
> > self.response.clear()
> > self.response.set_status(500)
> > self.response.out.write("This operation could not be
> > completed in time...")
>
> > logging.info("About to write normal result message")
> > self.response.out.write("This is the normal result message")
>
> > When I request "/test?sleep=30" I get the "502 Server Server Error"
> > page and the in my logs:
>
> > (E) 02-22 09:31PM 05.652
> > Ran out of time.
> > (I) 02-22 09:31PM 05.653
> > About to write normal result message
>
> > When I request "/test?sleep=0" I get the expected "This operation
> > could not be completed in time..." message page. Anyone know what's
> > up with this? Thanks for any help!
>
> > -Lenza
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---