Python挂线

2024-05-18 14:51:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

    final = []
    with futures.ThreadPoolExecutor(max_workers=self.number_threads) as executor:
        _futures = [executor.submit(self.get_attribute, listing,
                                    self.proxies[listings.index(listing) % len(self.proxies)]) for listing
                    in listings]
        for result in futures.as_completed(_futures):
            try:
                listing = result.result()
                final.append(listing)
            except Exception as e:
                print traceback.format_exc()
    return final

在self.get_属性提交给executor的函数以一个字典和代理作为输入,并发出一个或两个http请求来获取一些数据并返回一个经过编辑的字典。问题是工作线程在完成所有提交的任务时挂起。如果我提交400本字典,它将完成大约380个任务,然后挂起。如果我提交600,就可以完成570-580。不过,如果我提交25个,它将完成所有这些。我不确定从完成到不完成的门槛是多少。在

我也尝试过使用这样的队列和线程系统:

^{pr2}$

但是结果是一样的。如何修复/调试该问题?提前谢谢。在


Tags: 代码inselfforget字典asresult

热门问题