1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| from concurrent.futures import ThreadPoolExecutor from queue import Queue
class BoundedThreadPoolExecutor(ThreadPoolExecutor):
def __init__(self, max_workers=None, thread_name_prefix=''): super().__init__(max_workers, thread_name_prefix) self._work_queue = Queue(max_workers * 2) executor = BoundedThreadPoolExecutor(max_workers=8)
hrefs=['www.1.com','www.2.com','www.2.com'] for href in hrefs: executor.submit(parser_img, href)
executor.submit(parser_img, hrefs)
|