为什么我得到 NameError: name 'as_completed' is not defined(我从 concurrent.futures 导入 ThreadPoolExecutor)

时间:2021-02-16 21:53:30

标签: python threadpoolexecutor

我有以下代码:

从 concurrent.futures 导入 ThreadPoolExecutor

def load_database():
    with ThreadPoolExecutor(max_workers=10) as executor:
        futures = [executor.submit(load_person, x) for x in range(max_people - 1)]
        for future in as_completed(futures):
            return(future.result()) 
        print(futures)

我收到“NameError: name 'as_completed' 未定义”

我是否需要导入其他东西才能使用 as_completed?

谢谢, 克莉丝

1 个答案:

答案 0 :(得分:0)

as_completed 住在 concurrent.futures 所以你需要 from concurrent.futures import as_completed