【发布时间】:2018-02-15 05:40:03
【问题描述】:
我遇到以下问题。我想实现一个网络爬虫,到目前为止这工作但它太慢了,我试图使用多处理来获取 URL。
不幸的是,我在这个领域不是很有经验。
经过一些阅读,我认为最简单的方法是使用 multiprocessing.pool 中的 map 方法。
但我经常收到以下错误:
TypeError: Pickling an AuthenticationString object is disallowed for security reasons
我发现很少有相同错误的案例,很遗憾它们没有帮助我。
我创建了一个可以重现错误的代码的剥离版本:
import multiprocessing
class TestCrawler:
def __init__(self):
self.m = multiprocessing.Manager()
self.queue = self.m.Queue()
for i in range(50):
self.queue.put(str(i))
self.pool = multiprocessing.Pool(6)
def mainloop(self):
self.process_next_url(self.queue)
while True:
self.pool.map(self.process_next_url, (self.queue,))
def process_next_url(self, queue):
url = queue.get()
print(url)
c = TestCrawler()
c.mainloop()
如果有任何帮助或建议,我将不胜感激!
【问题讨论】:
标签: python python-3.x queue multiprocessing python-multiprocessing