多进程文件复制

#方法一
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()

猜你喜欢

转载自blog.csdn.net/weixin_42141853/article/details/80646355