Python 比较Gevent线程的结果
我正在使用gevent异步运行flask应用程序。我的主应用程序有:Python 比较Gevent线程的结果,python,flask,gevent,Python,Flask,Gevent,我正在使用gevent异步运行flask应用程序。我的主应用程序有: 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" 它使用略有不同的数
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"
它使用略有不同的数据运行,这些数据产生(来自fetch函数):
我只想返回一个u=True的字典,如果有多个字典,则返回第一个为True的字典。我怎样才能做到这一点呢?我会简单地写下这样的话:
...
result = gevent.joinall(threads)
for x in (t.value for t in threads):
if x.u:
return x
或:
...
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()