conquester
conquester

Reputation: 1132

Python Eventlet spawn not working

import eventlet

def foo():
    print('foo')

def main():
    eventlet.monkey_patch()
    pool = eventlet.GreenPool()
    pool.spawn(foo)

if __name__ == "__main__":
    main()

Expectation:

foo

But nothing happens, no print's. Why is this happening?

Upvotes: 3

Views: 706

Answers (1)

falsetru
falsetru

Reputation: 369244

You need to wait the spawned thread to finish, using eventlet.greenthread.GreenThread.wait:

thread = pool.spawn(foo)
thread.wait()

or using eventlet.greenpool.GreenPool.waitall:

pool.spawn(foo)
pool.waitall()

Upvotes: 4

Related Questions