from multiprocessing import Pool, Manager import os def copyFileTask(name, oldFolderName, newFolderName, queue): "完成copy一个文件的功能" fr = open(oldFolderName + "/" + name) fw = open(newFolderName + "/" + name, ‘w‘) content = fr.read() fw.write(content) fr.close() fw.close() queue.put(name) def main(): # 0. 获取要copy的文件夹的名字 oldFolderName = input("请输入文件夹的名字:") # 1.创建一个文件夹 newFolderName = oldFolderName + ‘-复件‘ os.mkdir(newFolderName) # 2.获取old文件夹中所有文件的名字 fileNames = os.listdir(oldFolderName) print(fileNames) # 3.使用多进程的方式copy原文件夹中的所有文件到新文件夹中 pool = Pool(5) # 进程池之间使用的Q queue = Manager().Queue() for name in fileNames: pool.apply_async(copyFileTask, args=(name, oldFolderName, newFolderName, queue)) pool.close() pool.join() print("拷贝完成") if __name__ == ‘__main__‘: main()