这样做安全吗?
@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
在最晚的时刻能够在后台获取实体时执行我的其他代码。