Search code examples
pythonthreadpoolexecutor

Why do I get NameError: name 'as_completed' is not defined (I have from concurrent.futures import ThreadPoolExecutor)


I have the following code:

from concurrent.futures import 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)

I am getting "NameError: name 'as_completed' is not defined"

Do I need to import something else to use as_completed?

Thanks, Chrissy


Solution

  • as_completed lives in concurrent.futures so you'll need from concurrent.futures import as_completed