python使用多个进程处理文件的问题



前面的问题已经解决:如何控制Python中用于调用外部命令的子进程的数量?

新的问题是,我如何批处理luanch cmd?示例代码可以正常操作,但只有最后一个文件执行在此处输入图像描述

def run(v):
for i in os.listdir(output_lineEdit):  #use "for" list all files
if i.split(".")[1] == "ma":  # use "if" choose ".ma" files
mapath = i
cmd = '"{mayaBatchPath}" -batch -file "{maPath}" -script "{melFile}" "{plugins}"'.format(
mayaBatchPath=MAYABATCHPATH,# mayabatch.exe path
melFile=melFile, #.mel files
maPath=output_lineEdit+"\"+mapath, # maya source files
plugins="-noAutoloadPlugins",
)
subprocess.run(cmd, shell=True)

def main():
with Pool(2) as pool:
pool.map(run, range(10))

if __name__ == '__main__':
main()

您忘记在循环中包含subprocess.run(cmd, shell=True)。因此,cmd字段只写入最后一次迭代,并且您使用它

最新更新