我有以下 Python 代码:
>>> import gevent
>>> from gevent import monkey; monkey.patch_all()
>>>
>>> def fooFn(k):
... return 'gevent_'+k
...
>>> threads = []
>>> threads.append(gevent.spawn(fooFn,'0'))
>>> threads.append(gevent.spawn(fooFn,'1'))
>>>
>>> gevent.joinall([threads[1]])
>>>
>>> print threads[1].value
gevent_1
>>> print threads[0].value
gevent_0
>>>
如上所示,threads[0].value
从fooFn
. 这意味着threads[0]
greenlet被执行了。
为什么当我只通过threads[1]
greenlet时会发生这种情况gevent.joinall
?
我怎样才能确保只执行那些实际传递给的greenlets gevent.joinall
?