App Engine中超时异常的名称是什么? [英] what is the name of the timeout exception in App Engine?

查看:114
本文介绍了App Engine中超时异常的名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我的印象是它被称为超时,但似乎不是。

For some reason, I was under the impression that it was just called Timeout, but it doesn't seem to be.

谢谢!

推荐答案

超时异常处理在请求定时器部分文档:

The timeout exception handling is explained in the Request Timer section of the docs:


请求处理程序的生成时间有限,并且返回对请求的响应,通常约为30秒。一旦达到最后期限,请求处理程序就被中断。

A request handler has a limited amount of time to generate and return a response to a request, typically around 30 seconds. Once the deadline has been reached, the request handler is interrupted.

Python运行时环境通过提高 DeadlineExceededError ,从包 google.appengine.runtime 。如果请求处理程序没有捕获此异常,与所有未捕获的异常一样,运行时环境将向客户端返回HTTP 500服务器错误。

The Python runtime environment interrupts the request handler by raising a DeadlineExceededError, from the package google.appengine.runtime. If the request handler does not catch this exception, as with all uncaught exceptions, the runtime environment will return an HTTP 500 server error to the client.

请求处理程序可以捕获这个错误来定制响应。运行时环境在提出异常以准备自定义响应后,给请求处理程序一点时间(少于一秒)。

The request handler can catch this error to customize the response. The runtime environment gives the request handler a little bit more time (less than a second) after raising the exception to prepare a custom response.

from google.appengine.runtime import DeadlineExceededError

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...")     

如果处理程序没有返回响应或者在第二个截止日期之前引发异常,处理程序将被终止,并返回默认错误响应。

If the handler hasn't returned a response or raised an exception by the second deadline, the handler is terminated and a default error response is returned.

虽然请求可能需要长达30秒的时间来响应,App引擎针对具有短期请求的应用程序进行了优化,通常需要几百毫秒的时间。高效的应用程序可以快速响应大多数请求。一个应用程序不会与App Engine的基础设施不能很好地匹配。

While a request can take as long as 30 seconds to respond, App Engine is optimized for applications with short-lived requests, typically those that take a few hundred milliseconds. An efficient app responds quickly for the majority of requests. An app that doesn't will not scale well with App Engine's infrastructure.

DataStore有自己的 TimeOut异常

The DataStore has its own TimeOut exception


google.appengine.ext.db 包提供了以下异常类:

The google.appengine.ext.db package provides the following exception classes:

[。 ..]

异常Timeout()

当数据存储区操作超过最大值时引发数据存储区操作允许的时间。

exception Timeout()
Raised when the datastore operation exceeds the maximum amount of time allowed for datastore operations.

这篇关于App Engine中超时异常的名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆