import eventlet
def foo():
print('foo')
def main():
eventlet.monkey_patch()
pool = eventlet.GreenPool()
pool.spawn(foo)
if __name__ == "__main__":
main()
期望:
FOO
但没有任何事情发生,没有印刷品。为什么会这样?
答案 0 :(得分:3)
您需要使用eventlet.greenthread.GreenThread.wait
thread = pool.spawn(foo)
thread.wait()
或使用eventlet.greenpool.GreenPool.waitall
:
pool.spawn(foo)
pool.waitall()