Checking when shutil.copyfile is done

落爺英雄遲暮 提交于 2020-04-07 10:36:01

问题


I have a such code:

for file in file_list:
    shutil.copyfile(file,newpath)
#do further actions

And here is the question, at #do further actions I use the copied f iles thus I need to make sure the shutil.copyfile functions finish their task. How can I make sure of this ?


回答1:


The shutil functions should return only after the operation is finished. If nothing funny is going on on the OS level it should be safe this way.

If you know the size of the file you could check if that is correct.




回答2:


copyfile is a blocking function. By the time you get to #do further actions it should always be done. Are you having issues where it isn't?



来源:https://stackoverflow.com/questions/61053704/how-to-block-the-shutitl-copy2-until-it-finish-the-copy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!