|
from gevent import monkey
import gevent
import urllib2
monkey.patch_all()
def run_task(url):
print 'Visit --> %s' % url
try:
response = urllib2.urlopen(url)
data = response.read()
print '%d bytes recevied from %s.' % (len(data),url)
except Exception,e:
print e
if __name__ == '__main__':
urls = ['https://github.com/','https://www.python.org','http://www.cnblogs.com/']
greenlets = [gevent.spawn(run_task,url) for url in urls]
gevent.joinall(greenlets)
运行时报错:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/gevent/monkey.py", line 192, in patch_all
File "build/bdist.linux-x86_64/egg/gevent/monkey.py", line 121, in patch_socket
File "build/bdist.linux-x86_64/egg/gevent/socket.py", line 731, in <module>
File "build/bdist.linux-x86_64/egg/gevent/ssl.py", line 392, in <module>
if not isinstance(purpose, _ASN1Object):
NameError: name 'PROTOCOL_SSLv3' is not defined
gevent安装的是gevent-0.13.1。
python菜鸟,请各位大神指教。代码是《Python爬虫开发与项目实战》中的协程一节实例
|
|