为什么这个Python函数不会返回未来?

时间:2012-10-31 02:51:03

标签: python google-app-engine

我正在使用带有NDB的Google App Engine。为简洁起见,我删除了很多代码,但保留了基本问题。我收到错误'list' object has no attribute 'get_result'

def get_future(keys):
    future = ndb.get_multi_async(keys)
    important_value = ... # get important value
    return {"future" : future, "value" : important_value}

dic = get_future(keys)
future = dic['future']
# error `'list' object has no attribute 'get_result'`
items = future.get_result()

为什么我在获得未来时会得到一份清单?

1 个答案:

答案 0 :(得分:8)

get_multi_async实际上会返回future个对象的列表,因此您需要在这些对象上调用.get_result()

Official definition

  

ndb.get_multi_async(keys,** ctx_options)

     

异步提取由传递的键序列标识的实体。

     

<强>参数

keys
 -Sequence of keys

**ctx_options 
 -Context options 
     

返回Future对象列表。如果未找到密钥,则每个future的结果都是Model实例或None。