Разрезать заполнение пакетного файла на куски
Импорт многопроцессорной обработки
def handle_batch_file(file_name):
# dummy code
# print(file_name)
return file_name
BATCH_SIZE = 5
BATCH_FILES = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
def main():
p = multiprocessing.Pool(BATCH_SIZE)
counter = 0
while True:
sub_list = BATCH_FILES[counter * BATCH_SIZE: (counter + 1) * BATCH_SIZE]
print('Calling "map" with sub list {}'.format(sub_list))
dummy_results = p.map(handle_batch_file, sub_list)
if len(BATCH_FILES) <= (counter + 1) * BATCH_SIZE:
break
counter += 1
if __name__ == "__main__":
main()
Вывод
Calling "map" with sub list ['a', 'b', 'c', 'd', 'e']
Calling "map" with sub list ['f', 'g', 'h', 'i', 'j']
Calling "map" with sub list ['k', 'l', 'm', 'n']