1

我想在捕获 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()
4

2 回答 2

2

如果请求通常在 60 秒内(对于 http 请求)或 10 分钟内(对于任务队列请求)未能返回并且 aDeadlineExceededError被抛出并且未被捕获,则请求被中止并返回 500 内部服务器错误。如果DeadlineExceededError被捕获但没有足够快地产生响应(您只有不到一秒),则请求被中止并返回 500 内部服务器错误。

有据可查:https ://developers.google.com/appengine/articles/deadlineexceedederrors

一旦DeadlineExceededError被捕获,您将有时间clean_up()使用taskqueueAPI添加要执行的任务

于 2013-07-20T18:39:00.103 回答
0

DeadlineExceededError 来自哪里?我认为截止日期是在某个地方初始化的,而不是硬编码的值。如果您下载源代码并查看 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
于 2013-07-20T07:06:56.920 回答