2
这样做是否安全?多次产生ndb.Future是否安全?
@ndb.tasklet
def foo():
# Note that I do not yield right here
future = some_key.get_async()
# Perform some other code
if some_condition:
# I need the get_async result here
entity = yield future
# I also need the get_async result here.
# If some_condition was true, I would be yielding this future
# for the second time. Is this ok?
entity = yield future
请不要告诉我,我可能只是yield
在函数的顶部,并在代码的其余部分使用entity
。我的实际功能比这更精细一点,我有一些条件代码路径可能需要使用entity
,我希望yield
在最后时刻能够执行我的其他代码,而实体正在背景。
如果App Engine在将来更改其实现会怎么样?如果记录在案,我会感到更有信心。我的猜测是,这实际上不会改变;我的观点是,目前的实施不是保证,也不应该依赖。 – allyourcode 2013-04-09 22:50:48
根据文档,你可以产生未来。屈服之后,未来仍然是未来吗? – tesdal 2013-04-16 19:33:10