python-3.x - Python重复了ThreadPoolExecutor的某些任务
问题描述
我正在尝试从 concurrent.futures 玩 ThreadPoolExecutor。
我的代码如下所示:
def f(x) 情况 1:返回 False 情况 2:返回 True
def runner(x):
out = set()
threads = []
export = []
while len(x)>0:
if len(x)<21:
workers = len(x)
else:
workers =20
with ThreadPoolExecutor(max_workers=workers) as executor:
for v in x:
threads.append(executor.submit(my_job, v))
for task in as_completed(threads):
export_dict =task.result()
if export_dict:
export.append(export_dict)
else:
out.add(number)
x = list(out)
return export, out
while len(un_done)>0:
export, un_done = runner(un_done)
print(un_done)
#write_mongo(db_name='CDR',coll_name='cdr',v=to_cdr)
write_mongo(db_name='NumberHistory', coll_name='numberhistory', v=export)
我的意图是在一个新线程上重复所有失败的任务。所以我想重复 runner 函数,直到我从所有 f(x) 中得到 True。我最终得到了很多永远不会结束的重复性任务。
解决方案
推荐阅读
- python - 按经纬度选择数据
- java - 声纳立方体未正确显示 Java 项目的测试覆盖率
- android - Arraylist 数据自动清空
- angular - 无法绑定到“种类”,因为它不是“ngx-fs-icon”的已知属性
- java - 使用 Apache Ignite 一些过期数据保留在内存中,启用 TTL 并在线程执行后
- python - “系列”对象不可调用
- javascript - 如何使用多个复制到剪贴板按钮创建弹出警报?
- .net-core - 如何在 CardAction 中的标题中获取粗体文本
- ssh - 哪个模块加载请求的库?
- vue.js - 如何将属性从父模板传递到vuejs中的插槽