检查 Shutil.copyfile 何时完成
我有这样的代码:
for file in file_list:
shutil.copyfile(file,newpath)
#do further actions
这是问题,在 #do future actions
我使用复制的文件,因此我需要确保 shutil.copyfile
函数完成它们的工作任务。我怎样才能确定这一点?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Shutil 函数应仅在操作完成后返回。如果操作系统级别没有发生任何有趣的事情,那么这种方式应该是安全的。
如果您知道文件的大小,您可以检查这是否正确。
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.
copyfile
是一个阻塞函数。当您进行#do future actions
时,它应该始终已完成。您是否遇到了不存在的问题?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?