with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
    fs = [executor.submit(process_file, file) for file in files]
concurrent.futures.wait(fs)
Как ограничить количество одновременных потоков в Python?