利志分享
fast_forward
view_headline
开发工具箱
go教程
clickhouse教程
kafka教程
python教程
shell教程
原创杂文
打赏
开发工具箱
go教程
clickhouse教程
kafka教程
python教程
shell教程
原创杂文
打赏
python基础
python输入输出及编码和注释
python的数据基础数据类型
python的list和tuple数据结构
python的条件语句和循环
python的dict和set的使用
python的函数使用
python的io操作
python操作mysql
python的协程使用
python 的 gevent 协程库使用
目录
python基础
python输入输出及编码和注释
python的数据基础数据类型
python的list和tuple数据结构
python的条件语句和循环
python的dict和set的使用
python的函数使用
python的io操作
python操作mysql
python的协程使用
python 的 gevent 协程库使用
python 的 gevent 协程库使用
阅读:1573
分享次数:0
# 10.py #code=utf-8 # # python 的 gevent 协程库使用 # 首先安装greelet,方式:pip install greenlet。下载gevent包,地址:https://pypi.python.org/packages/12/dc/0b2e57823225de86f6e111a65d212c9e3b64847dddaa19691a6cb94b0b2e/gevent-1.1.1.tar.gz#md5=1532f5396ab4d07a231f1935483be7c3,tar -zxvf 解压之后 执行python setup.py install import gevent from gevent.queue import Queue def func1(): print 'start func1' gevent.sleep(1) print 'end func1' def func2(): print 'start func2' gevent.sleep(1) print 'end func2' gevent.joinall( [ gevent.spawn(func1), gevent.spawn(func2) ] ) # 下面测试队列的使用 def func3(): for i in range(10): print 'int the func3' q.put('test') def func4(): for i in range(10): print 'int the func4' res = q.get() print '---->', res q = Queue() gevent.joinall( [ gevent.spawn(func3), gevent.spawn(func4) ] ) ''' 此打印结果:说明这两个func都进行执行了,然后都执行了start,end是后面执行结果 start func1 start func2 end func1 end func2 int the func3 int the func3 int the func3 int the func3 int the func3 int the func3 int the func3 int the func3 int the func3 int the func3 int the func4 ----> test int the func4 ----> test int the func4 ----> test int the func4 ----> test int the func4 ----> test int the func4 ----> test int the func4 ----> test int the func4 ----> test int the func4 ----> test int the func4 ----> test '''
感觉本站内容不错,读后有收获?
attach_money
我要小额打赏,鼓励作者写出更好的教程
扫码关注公众号:talk_lizhi