python协程io自动切换--gevent

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python协程io自动切换--gevent相关的知识,希望对你有一定的参考价值。

1.gevent执行

import gevent

def func1():
    print(‘func1 start‘)
    gevent.sleep(2)
    print(‘func1 end‘)

def func2():
    print(‘func2 start‘)
    gevent.sleep(1)
    print(‘func2 end‘)

def func3():
    print(‘func3 start‘)
    gevent.sleep(0)
    print(‘func3 end‘)

if __name__==‘__main__‘:
    gevent.joinall([
        gevent.spawn(func1),
        gevent.spawn(func2),
        gevent.spawn(func3),

    ])

>>:
func1 start
func2 start
func3 start
func3 end
func2 end
func1 end       

以上是关于python协程io自动切换--gevent的主要内容,如果未能解决你的问题,请参考以下文章

python的gevent协程

gevent 协程 使用

006py协程gevent

多协程间遇到IO自动切换gevent

并发编程之协程

协程:gevent模块,遇到i/o自动切换任务 038