python 协程 gevent
import gevent
def f1():
print("print in f1")
gevent.sleep(2)
print("switch to foo again")
def f2():
print("print in f2")
gevent.sleep(1)
print("switch to f2 again")
def f3():
print("print in f3")
gevent.sleep(0)
print("switch to f3 again")
gevent.joinall([
gevent.spawn(f1),
gevent.spawn(f2),
gevent.spawn(f3)
])
'''result:
print in f1
print in f2
print in f3
switch to f3 again
switch to f2 again
switch to foo again
'''