#方法一 import os,time from multiprocessing import Pool #实现文件的拷贝 def copyFile(rpath,wpath): with open(rpath,'rb') as fr: content=fr.read() with open(wpath,'wb') as fw: fw.write(content) rpath=r'C:\Users\lucky\Desktop\project' wpath=r'C:\Users\lucky\Desktop\copyp' filelist=os.listdir(rpath) for fileName in filelist: copyFile(os.path.join(rpath,fileName),os.path.join(wpath,fileName)) #方法二 import os,time from multiprocessing import Pool #实现文件的拷贝 def copyFile(rpath,wpath): with open(rpath,'rb') as fr: content=fr.read() with open(wpath,'wb') as fw: fw.write(content) if __name__=='__main__': rpath=r'C:\Users\lucky\Desktop\project' wpath=r'C:\Users\lucky\Desktop\copyp' filelist=os.listdir(rpath) pp=Pool(2) for fileName in filelist: pp.apply_async(copyFile,args=(os.path.join(rpath,fileName),os.path.join(wpath,fileName))) pp.close() pp.join()
多进程文件复制
最新推荐文章于 2023-04-25 12:52:22 发布