我正在使用Pool函数使用python脚本运行一组命令行可执行文件(〜200)。我从.csv文件导入命令行可执行文件。我在具有96个核心的机器上的AWS实例上运行。但是我注意到我的cpu利用率是100%。执行完Pool实例后,我需要关闭它吗?
import csv
from multiprocessing import Pool
import subprocess
def import_executables(file):
f = open(file)
csv_f = csv.reader(f)
executables = []
for row in csv_f:
executables.append(row[0])
executables_tuple = tuple([name] for name in executables)
return executables_tuple
work = import_executables('output.csv')
def work_log(work_data):
print("Process %s executing" % (work_data))
subprocess.call(work_data, shell=True)
def pool_handler():
p = Pool(10)
p.map(work_log, work)
if __name__ == "__main__":
pool_handler()