我有一个Python脚本使用shutil.copy2号文件广泛的。因为我用它在网络上复制文件,所以经常出现I/O错误,导致程序执行失败:
Traceback (most recent call last):
File "run_model.py", line 46, in <module>
main()
File "run_model.py", line 41, in main
tracerconfigfile=OPT.tracerconfig)
File "ModelRun.py", line 517, in run
self.copy_data()
File "ModelRun.py", line 604, in copy_ecmwf_data
shutil.copy2(remotefilename, localfilename)
File "/usr/lib64/python2.6/shutil.py", line 99, in copy2
copyfile(src, dst)
File "/usr/lib64/python2.6/shutil.py", line 54, in copyfile
copyfileobj(fsrc, fdst)
File "/usr/lib64/python2.6/shutil.py", line 27, in copyfileobj
buf = fsrc.read(length)
IOError: [Errno 5] Input/output error
我怎样才能避免程序的执行中止并让它重试复制过程呢?在
我使用的代码已经通过检查文件大小来检查文件是否已完全复制:
^{pr2}$
你可以用
抓住错误并加以处理
看看this
哪个块出错了?只需在其周围加上try/except:
相关问题 更多 >
编程相关推荐