gevent携程,自动切换(IO)


import gevent

def foo():
print('Running in foo')
gevent.sleep(2)
print('Explicit context switch to foo again')
def bar():
print('Explicit精确的 context内容 to bar')
gevent.sleep(1)
print('Implicit context switch back to bar')
def func3():
print("running func3 ")
gevent.sleep(0)
print("running func3 again ")


gevent.joinall([
gevent.spawn(foo), #生成,
gevent.spawn(bar),
gevent.spawn(func3),
])


#=======================

Running in foo
Explicit精确的 context内容 to bar
running func3
running func3 again
Implicit context switch back to bar
Explicit context switch to foo again

posted @   rongye  阅读(242)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示