import gevent
from gevent import monkey
import urllib.request
# 有耗时操作时需要
monkey.patch_all()
def my_download(url):
print “GET: %s”%(url, )
resp = urllib.request.urlopen(url)
data = resp.read()
print "%d bytes received from %s."%(len(data), url)
gevent.joinall([
gevent.spawn(my_downlad, "http://www.baidu.con/"),
gevent.spawn(my_downlad, "http://www.itcast.cn/"),
gevent.spawn(my_downlad, "http://www.itheima.con/")
])
网友评论