【发布时间】:2013-06-21 01:57:19
【问题描述】:
TL;DR:
如何解决 Appengine 中的这个错误:有时is_shutting_down 返回 False,然后在一两秒内关闭实例?
详情
我在 Google Appengine 应用程序 (Python) 上有一个后端实例。后端实例用于生成报告,有时需要几分钟甚至几小时才能完成。
为了处理意外关闭,我正在关注runtime.is_shutting_down(),并在is_shutting_down 返回True 时将报告的中间状态存储到DB 中。
这是我检查它的代码部分:
from google.appengine.api import runtime
#...
def my_report_function():
#...
# Check if we should interrupt and reschedule to avoid timeout error.
duration_sec = time.time() - start
too_long = MAX_SEC < duration_sec
is_shutting_down = runtime.is_shutting_down()
log.debug('Does this report iteration need to wrap it up soon? '
'Too long? %s (%s sec). Shutting down? %s'
% (too_long, duration_sec, is_shutting_down))
if too_long or is_shutting_down:
# save the state of report, reschedule next iteration, and return
有时它有效,但有时我会在 Appengine 日志中看到以下内容:
D 2013-06-20 18:41:56.893 Does this report iteration need to wrap it up soon? Too long? False (348.865950108 sec). Shutting down? False
E 2013-06-20 18:42:00.248 Process terminated because the backend took too long to shutdown.
很明显,从我检查runtime.is_shutting_down() 返回的值到 Appengine 杀死后端之间,30 秒的超时还没有过去。
有人知道为什么会发生这种情况,是否有解决方法?
提前谢谢你!
【问题讨论】:
标签: python google-app-engine timeout backend