异常情况
在实现多进程爬虫的时候,打包为exe后,发现在windows环境下进程异常退出。查看文档后发现在windows环境下要在主函数增加multiprocessing.freeze_support()。
Code
# 进程执行的爬虫操作
def start_crawler():
# statement
if __name__ == '__main__':
# 创建进程前加入multiprocessing.freeze_support()
import multiprocessing
multiprocessing.freeze_support()
CRAWLER_WORKERS = 10
crawler_list = []
for i in range(CRAWLER_WORKERS):
p = Process(target=start_crawler)
crawler_list.append(p)
for crawler in crawler_list:
crawler.start()
for crawler in crawler_list:
crawler.join()