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 <le...@aznel.trickip.net> 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
> (see http://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 google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to