使用gevent批量爬取网页,因为页面较多,不适合创建出所有的greenlet再执行,
所以用gevent.pool来做。加入到pool中的greenlet可以正常运行,但运行结束后
并没有释放pool的空间,导致pool被占满,后续任务无法执行。
代码:
g = Pool(1000)
while not urlQue.empty():
url = urlQue.get().strip()
g.add(g.start(gevent.spawn(thread,url)))
def thread(url):
b = downloadWorker.DownloadWorker(url)
b.run()
del b