我正在与gevent异步运行一个烧瓶应用程序。我的主要应用程序有:
def multiple():
..........
threads = [gevent.spawn(fetch, data for i in range(2)]
result = gevent.joinall(threads)
print [thread.value for thread in threads]
return "DICTIONARY GOES HERE"
这种情况稍有不同,产生(来自获取函数):
{u': False, 'delete_at': 1438759341.674, 'id': 43, 'fa': 5.4, 'created_at': 1438701741.674 }
{u': True, 'delete_at': 1438759341.675, 'id': 44, 'fa': 9.3, 'created_at': 1438701741.675 }
{u': False, 'delete_at': 1438759341.675, 'id': 47, 'fa': 4.7, 'created_at': 1438701741.675 }
我想只返回一个u = True的字典,或者第一个字典,如果有多个则返回true。我怎么能这样做?
答案 0 :(得分:1)
我只想写下这样的东西:
...
result = gevent.joinall(threads)
for x in (t.value for t in threads):
if x.u:
return x
或:
...
result = gevent.joinall(threads)
return (t.value for t in threads if t.u).next()