------------ GET: https://www.baidu.com/ GET: http://docs.20150509.cn/ GET: http://www.20150509.cn/ 1314 bytes received from http://www.20150509.cn/. 227 bytes received from https://www.baidu.com/. 37491 bytes received from http://docs.20150509.cn/.
from gevent import monkey; monkey.patch_all() import gevent import requests
deffunc(url): print('GET: %s' % url) resp = requests.get(url) data = resp.text print('%d bytes received from %s.' % (len(data), url))
urls = ['https://www.baidu.com/', 'http://docs.20150509.cn/', 'http://www.20150509.cn/'] glist = [] for i in range(len(urls)): glist.append(gevent.spawn(func, urls[i])) print(glist) gevent.joinall(glist)
------------ [<Greenlet at 0x103396470: func('https://www.baidu.com/')>, <Greenlet at 0x103396638: func('http://docs.20150509.cn/')>, <Greenlet at 0x103396768: func('http://www.20150509.cn/')>] GET: https://www.baidu.com/ GET: http://docs.20150509.cn/ GET: http://www.20150509.cn/ 1314 bytes received from http://www.20150509.cn/. 227 bytes received from https://www.baidu.com/. 37491 bytes received from http://docs.20150509.cn/.