获得DeadlineExceededError后我有多少时间?

时间:2013-07-20 02:42:30

标签: python google-app-engine

我想在捕获DeadlineExceededError后正确退出。我有多少钱要清理?

例如,

try:
  do_some_work()
except DeadlineExceededError:
  # How much more time do I have here?
  # Can clean_up() be as long as 1s, 5s, or longer?
  clean_up()
  return
more_work()

2 个答案:

答案 0 :(得分:2)

如果请求通常在60秒内没有为http请求返回,或者10分钟内没有为任务队列请求返回并且DeadlineExceededError被抛出而没有被捕获,则请求被中止并返回500内部服务器错误。如果DeadlineExceededError被捕获但响应生成得不够快(您的时间少于一秒),请求将中止,并返回500内部服务器错误。

在此记录良好:https://developers.google.com/appengine/articles/deadlineexceedederrors

抓住DeadlineExceededError后,您将有时间使用clean_up() API

添加执行taskqueue的任务

答案 1 :(得分:0)

DeadlineExceededError来自哪里?我认为截止日期是在某个地方初始化的,而不是硬编码的值。如果您download the source code并查看google.appengine.api.apiproxy_rpc.py,则可以查看初始值设定项。

class RPC(object):
"""Base class for implementing RPC of API proxy stubs.

To implement a RPC to make real asynchronous API call:
- Extend this class.
- Override _MakeCallImpl and/or _WaitImpl to do a real asynchronous call.
"""

IDLE = 0
RUNNING = 1
FINISHING = 2

def __init__(self, package=None, call=None, request=None, response=None,
           callback=None, deadline=None, stub=None):
"""Constructor for the RPC object.

All arguments are optional, and simply set members on the class.
These data members will be overriden by values passed to MakeCall.

Args:
  package: string, the package for the call
  call: string, the call within the package
  request: ProtocolMessage instance, appropriate for the arguments
  response: ProtocolMessage instance, appropriate for the response
  callback: callable, called when call is complete
  deadline: A double specifying the deadline for this call as the number of
            seconds from the current time. Ignored if non-positive.
  stub: APIProxyStub instance, used in default _WaitImpl to do real call
"""
self.__exception = None
self.__state = RPC.IDLE
self.__traceback = None

self.package = package
self.call = call
self.request = request
self.response = response
self.callback = callback
self.deadline = deadline
self.stub = stub
self.cpu_usage_mcycles = 0