2013-07-20 68 views
1

我想在捕獲DeadlineExceededError後正確退出。我還有多少錢要清理?獲得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() 
+0

以我的經驗不到一秒執行clean_up(),我還沒有看到一個證明了這一點,並且你並不總是得到寬限期,這很大程度上取決於你爲什麼得到DEE。 –

回答

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 
+0

感謝您指出了代碼,但是我沒有看到特別指出DeadlineExceededError後的寬限期的任何內容。 – Sam

2

如果請求不能在60秒內通常返回HTTP請求,或10分鐘爲任務隊列中的請求和一個DeadlineExceededError被拋出並沒有被捕獲,則該請求被中止並返回500內部服務器錯誤。如果DeadlineExceededError被捕獲但響應沒有足夠快地產生(您有不到一秒),則請求被中止並返回500內部服務器錯誤。

有據可查的位置:https://developers.google.com/appengine/articles/deadlineexceedederrors

一旦DeadlineExceededError被捉住,你會得到一個時間添加任務使用taskqueue API