【发布时间】:2015-10-02 08:43:31
【问题描述】:
我不确定如何在 Google App Engine 中处理异步操作。你能帮我看看这段代码吗?
我要异步放置实体:
class Thing(ndb.Model):
pass
entity = Thing()
future = entity.put_async()
# hundred of code lines of other async to parallelize
但我不确定是否应该在处理程序结束之前等待这个 put?
我应该完成我的代码以保持数据一致吗?
future.wait()
也许我的问题看起来微不足道,但我想避免来自意外行为的随机错误。我读了https://cloud.google.com/appengine/docs/python/ndb/futureclass,但在这里没有找到好的答案。
https://cloud.google.com/appengine/docs/python/ndb/async 也一样。
【问题讨论】:
-
如果要等待异步方法完成,为什么还要使用它?
-
@TimCastelijns 因为我想使用
put_async()而不是put()。代码被简化。不要以为我不知道如何使用put()假设我必须使用put_async()并且跳过了数百行代码。
标签: python google-app-engine google-cloud-datastore app-engine-ndb