协程
2018-08-12 本文已影响0人
裴general
[https://www.bilibili.com/read/cv846395 ]
[https://www.cnblogs.com/zhangxinqi/p/8337207.html]
def gevent_fun():
from gevent import monkey
monkey.patch_all(socket=True,select=True)
from gevent.pool import Pool
gevent_pool = Pool(800)
urls = [urlx for i in range(1000000)]
gevent_pool.map(fun, urls)
======================
from gevent import monkey;
monkey.patch_all()
import gevent, requests
def get_page(url):
ret = requests.get(url).text
print(ret)
# g1 = gevent.spawn(get_page, 'http://www.openstack.org')
g2 = gevent.spawn(get_page, 'https://www.python.org')
g3 = gevent.spawn(get_page, 'http://www.sina.com.cn/')
gevent.joinall([g2, g3])