import os
import multiprocessing
def copy_work(source_dir,dest_dir,file_name):
print(multiprocessing.current_process())
source_path = source_dir+"/"+file_name
dest_path = dest_dir+ "/"+file_name
print(source_path,"------>",dest_path)
with open(source_path,"rb") as source_file:
with open(dest_path,"wb") as dest_file:
while True:
file_data = source_file.read(1024)
if file_data :
dest_file.write(file_data)
else:
break
if __name__ == "__main__":
source_dir =input()
dest_dir ="./dest"
try:
os.mkdir("./dest")
except Exception as e:
print("文件已存在!")
file_list = os.listdir("./test")
print(file_list)
pool = multiprocessing.Pool(3)
for file_name in file_list:
print(file_name)
pool.apply_async(copy_work,(source_dir,dest_dir,file_name))
pool.close()
pool.join()
pass