我已經經歷了谷歌雲NDB異步NDB異步接入兼容性examles教程與GAE
https://cloud.google.com/appengine/docs/standard/python/ndb/async
您可以指定一個整體WSGIApplication會爲ndb.toplevel。這使得 確信每個WSGIApplication的處理程序在返回之前都會等待所有異步 請求。 (它沒有「頂層」的所有 WSGIApplication會的處理器。)
app = ndb.toplevel(webapp2.WSGIApplication([('/', MyRequestHandler)]))
這是與瓶兼容相同的功能?例如我的代碼
app = Flask(__name__)
app.config.update(DEBUG = not SERVER_ISPRODUCTION)
app = ndb.toplevel(app)
...
@app.route('/test')
def testBackfill():
給我的錯誤
Traceback (most recent call last):
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
@app.route('/test')
AttributeError: 'function' object has no attribute 'route'
此錯誤消失時,我直接移到頂層回到請求處理。 我覺得任何瓶子都不能用這個功能,或者我在如何使用頂層時做錯了什麼。 我的意圖是讓我的應用程序中的每個請求處理程序在退出之前等待所有異步Google DataStore調用完成(我在請求處理程序中使用yield語句和tasklet)。
這可以解決上述問題。用燒瓶頂級工作的更大問題仍然存在。當我按照描述運行時,它看起來像我的應用程序正在退出而不等待異步ndb調用返回yield。我正在使用get_or_insert_async函數,該函數似乎不會在應用程序退出響應之前退出數據存儲區。代替燒瓶與ndb的兼容性,你知道哪些框架可以很好地與async ndb配合使用? webapp2的? – Dave
是的,webapp2適合我。但我只在處理程序的get/set方法級別使用了'ndb.toplevel',而不是在應用程序級別。 –