有个即时爬虫的需求,每一次请求过来,就去网站爬取多条数据,所以用到了 gevent.spawn,代码如下
spawns =[]
for param in param_list:
spawns.append(gevent.spawn(s_search, param))
gevent.joinall(spawns)
s_search 是具体的爬取的代码,第一次请求的时候正常,第二次请求异常,第三次又正常了,就这样正常一次,错误一次。异常如下:
File "C:\Users\duanbingjie\PycharmProjects\IpProxy\IpProxy\IPrice.py", line 107, in get_price
gevent.joinall(spawns)
File "C:\python27\lib\site-packages\gevent\greenlet.py", line 649, in joinall
return wait(greenlets, timeout=timeout, count=count)
File "C:\python27\lib\site-packages\gevent\hub.py", line 1038, in wait
return list(iwait(objects, timeout, count))
File "C:\python27\lib\site-packages\gevent\hub.py", line 985, in iwait
item = waiter.get()
File "C:\python27\lib\site-packages\gevent\hub.py", line 939, in get
Waiter.get(self)
File "C:\python27\lib\site-packages\gevent\hub.py", line 899, in get
return self.hub.switch()
File "C:\python27\lib\site-packages\gevent\hub.py", line 630, in switch
return RawGreenlet.switch(self)
LoopExit: ('This operation would block forever', <Hub at 0x987f030 select pending=0 ref=0>)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.