Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ndb aysnc“;“下一个收益率”;要使用get_multi_async_Python_Google App Engine_App Engine Ndb - Fatal编程技术网

Python ndb aysnc“;“下一个收益率”;要使用get_multi_async

Python ndb aysnc“;“下一个收益率”;要使用get_multi_async,python,google-app-engine,app-engine-ndb,Python,Google App Engine,App Engine Ndb,对于ndb.get\u multi\u async调用,是否有一种内置或规范的方法来使用第一个和所有后续结果 我希望,这说明,它大致如下: def yield_next(futures): while futures: yield ndb.Future.wait_any(futures) # We have to remove the yielded future from the futures. # How do we know which future

对于
ndb.get\u multi\u async
调用,是否有一种内置或规范的方法来使用第一个和所有后续结果

我希望,这说明,它大致如下:

def yield_next(futures):
   while futures:
     yield ndb.Future.wait_any(futures)
     # We have to remove the yielded future from the futures.
     # How do we know which future was removed?
     # ... futures.remove(???)

for model in yield_next(ndb.get_multi_async(keys)):
   ...
删除已消耗的未来的一种方法是检查
期货
,查看是否已完成。 存在一个固有的竞争条件:如果任何期货同时完成,或者在
remove
调用之前的任何情况下,可以执行
futures
的多个元素。除此之外,我还不知道有什么可靠的方法来确定哪个未来被消耗掉了

人们可能会认为这是一个相当普遍的模式,但我还没有看到它得到解决。通过查看
ndb/tasklets.py
似乎有一些奇异的(阅读:未记录的)可能性,如
减少未来
多未来
,但我从未使用过它们。也许答案在于微线程本身。

很简单——只需使用一组:

futures = set(futures)
while futures:
    f = ndb.Future.wait_any(futures)
    futures.remove(f)
    yield f