我已经经历了谷歌云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',而不是在应用程序级别。 –