python之小白的多线程小练习-利用多线程拷贝文件夹中的所有文件

import os,sys
from multiprocessing import Pool
from multiprocessing import Manager



def copy_file(name,path,new_path,q):
    fr=open(path+"/"+name)
    fw=open(new_path+'/'+name,"w")
    content=fr.read()
    fw.write(content)
    fr.close()
    fw.close()
    q.put(name)




def run():
    path=input("请输入您要拷贝的路径:")

    new_path=path+"-复件"
    os.mkdir(new_path)
    filename=os.listdir(path)
    pool=Pool(5)

    q=Manager().Queue()

    for name in filename:
        pool.apply_async(copy_file,args=(name,path,new_path,q))


    num=0
    allnum = len(filename)
    while num

你可能感兴趣的:(python作业的小练习)