我在python 2.7中测试了gevent和greenlet的一些功能。 这是我的代码:
from gevent import monkey;monkey.patch_socket()
import gevent, random, urllib2
from time import sleep
from greenlet import greenlet
from Queue import Queue
def f(url):
print ('GET: %s' % url)
resp = urllib2.urlopen(url)
data = resp.read()
print ('%d bytes received from %s.' % (len(data),url))
gevent.joinall([
gevent.spawn(f,'https://www.python.org/'),
gevent.spawn(f,'https://www.yahoo.com/'),
gevent.spawn(f,'https://github.com/')
])
错误来自
URLError: <urlopen error The operation did not complete (read) (_ssl.c:590)>
Thu Aug 24 14:26:30 2017 <Greenlet at 0x2d763a0: f('https://github.com/')> failed with URLError
和另外2个网址。有什么想法解决这个问题吗?