我使用的URLFetch從谷歌AppEngine上,我添加了最後期限參數,以強制期限要短(3秒),如下所示:AppEngine上的網址抓取,如何強制超時被尊重
try:
urlfetch.set_default_fetch_deadline(3)
return urlfetch.fetch(url='http://www.example.com', method=urlfetch.GET, deadline=3)
except google.appengine.runtime.apiproxy_errors.DeadlineExceededError:
pass
except google.appengine.api.urlfetch_errors.DeadlineExceededError:
pass
return None
但無論如何,我的線程持續60秒(Appengine上的http請求的最大執行時間),然後在DeadlineException(「線程在請求後運行」)失敗。
有沒有辦法確保上面的查詢將在3秒內嚴格停止?
你確定這個異常不是真的引發,而是被你的代碼捕獲和忽略嗎?也許嘗試用'logging'調用替換'pass'語句來檢查? –
我相信'set_default_fetch_deadline()'是用於使用'rpc'和'urlfetch.make_fetch_call()'的。你的'urlfetch.fetch(... deadline = 3)'應該就足夠了。嘗試添加一個通用的'except:'並且在裏面以及另一個'excepts'裏登錄。 – GAEfan
沒有明顯的截止日期參數已經被完全移除,現在需要使用'set_default_fetch_deadline'。請參閱文檔:https://cloud.google.com/appengine/docs/standard/python/issue-requests?csw=1 –