Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AirSpider爬虫的parse函数中使用ThreadPoolExecutor线程池报错误 #283

@yjm2018

Description

@yjm2018

我想在AirSpider爬虫中的parse函数中使用ThreadPoolExecutor线程池实现并发下载图片,但是会报错误:|cannot schedule new futures after interpreter shutdown。
我的python是3.10.
代码类似下面:

def parse(self, request, response):
    with ThreadPoolExecutor(max_workers=10) as executor:
        tasks = []
        for i in range(1, 10):
            tasks.append(executor.submit(math.sqrt, i))
        for future in tasks:
            print(future.result())

请问大佬这是什么原因?如果我想实现图片并发下载该如何实现(我想把下载后的图片路径写入item中)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions