demo_thread_pool_executor.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:SmallReptileTraining 作者: yanbober 项目源码 文件源码
def runner(self):
        thread_pool = ThreadPoolExecutor(max_workers=2, thread_name_prefix='DEMO')
        futures = dict()
        for url in self.urls:
            future = thread_pool.submit(self.get_web_content, url)
            futures[future] = url

        for future in concurrent.futures.as_completed(futures):
            url = futures[future]
            try:
                data = future.result()
            except Exception as e:
                print('Run thread url ('+url+') error. '+str(e))
            else:
                print(url+'Request data ok. size='+str(len(data)))
        print('Finished!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号