用Python使用Google應用服務引擎(GAE)隨手記錄

資料來源:http://code.google.com/intl/zh-TW/appengine/docs/python/runtime.html

==========

from google.appengine.runtime import DeadlineExceededError

class MainPage(webapp.RequestHandler):
def get(self):
try:
# Do stuff…

except DeadlineExceededError:
self.response.clear()
self.response.set_status(500)
self.response.out.write(“This operation could not be completed in time…”)

如果處理常式無法在第二個期限內傳回回應或引發例外狀況,處理常式將終止並傳回預設的錯誤回應。

/////

下列範例示範快取匯入模組的方式。因為單一網頁伺服器只會匯入一次 mymodule,全域 mymodule.counter 只會在伺服器第一次服務要求時初始化為 0。後續的要求會使用之前要求的值。 Continue reading “用Python使用Google應用服務引擎(GAE)隨手記錄”