with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
    fs = [executor.submit(process_file, file) for file in files]
for f in concurrent.futures.as_completed(fs):
    do_something(f.result())
How to limit number of concurrent threads in Python?