import gevent
from gevent.event import AsyncResult
import time
class Job(object):
def __init__(self, name):
self.name = name
def setter(job):
print 'starting'
gevent.sleep(3)
job.result.set('%s done' % job.name)
def waiter(job):
print job.result.get()
# event loop
running = []
for i in range(5):
print 'creating'
j = Job(i)
j.result = AsyncResult()
running.append(gevent.spawn(setter, j))
running.append(gevent.spawn(waiter, j))
print 'started greenlets, event loop go do something else'
time.sleep(5)
gevent.joinall(running)
GEVENT犯規真正開始,直到joinall
被稱爲Python的事件循環瓦特/ GEVENT
- 有一些會異步啓動/產卵GEVENT(它爲什麼不盡快菌種被稱爲馬上開始)?
- 是否有
select
/epoll在運行greenlet上查看哪一個需要加入而不是joinall()
?