调用字程序sub_process= multiprocessing.process(target=copy_file,args=(file_name,source_dir,dest_dir))然后报错TypeError: 'module' object is not callable。 我得pip list有这个模块,为啥显示调用不了
4条回答 默认 最新
- CSDN专家-HGJ 2021-04-14 10:03关注
process 的P要大写,sub_process= multiprocessing.Process(target=copy_file,args=(file_name,source_dir,dest_dir));路径传入错误,改source_dir,dest_dir为source_path,dest_path;写入文件的地方没有传入写入内容。改成如下就能运行。
from multiprocessing import Process import os def copy_file(source_dir,dest_dir): file_list = os.listdir(source_dir) for file_name in file_list: source_path=source_dir+'/'+file_name dest_path=dest_dir+'/'+file_name with open(source_path,'rb') as source_file: with open(dest_path,'wb') as dest_file: while True: data=source_file.read(1024) if data: dest_file.write(source_file.read()) else: break if __name__ == '__main__': source_dir = 'F:/2021/answerQ/data/trainer' dest_dir = 'F:/2021/answerQ/data/2017' sub_process = Process(target=copy_file, args=(source_dir, dest_dir)) sub_process.start() sub_process.join()
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1