一、多进程案例报错源地址不存在 问题遇到的现象和发生背景 :
在linux系统,pycharm实现多进程复制文件
二、用代码块功能插入代码,请勿粘贴截图
import os
import multiprocessing
def copy_file(file_name,source_dir,dest_dir):
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(data)
else:
break
if __name__=="__main__":
source_dir="/home/lila/PycharmProjects/untitled/python"
dest_dir="/home/Desktop/test"
#print(os.getcwd())
#print(os.path.abspath('.'))
try:
os.mkdir(dest_dir)
except:
print("mu biao wen jian jia yi jing cun zai ")
file_list=os.listdir(source_dir)
print(file_list)
for file_name in file_list:
sub_process=multiprocessing.Process(target=copy_file,args=(file_name,source_dir,dest_dir))
sub_process.start()
三、 运行结果及报错内容
/usr/bin/python3.5 /home/lila/PycharmProjects/untitled/hm_02_example_mutleprocess.py
mu biao wen jian jia yi jing cun zai
Traceback (most recent call last):
File "/home/lila/PycharmProjects/untitled/hm_02_example_mutleprocess.py", line 30, in
file_list=os.listdir(source_dir)
FileNotFoundError: [Errno 2] No such file or directory: './home/lila/PycharmProjects/untitled/python'