python - 复制文件时出现 FileNotFoundError
问题描述
我在 Ubuntu 18.04 上使用 python 3.8 工作,并且我有一个间歇性的shutil.copy2
功能异常:
def copy_file(src, dst):
assert os.path.exists(src), "Source file does not exist"
assert os.path.exists(dst), "Destination folder does not exist"
shutil.copy2(src, dst)
随机地,对于同一个文件/文件夹,此函数会在子函数中引发FileNotFoundError
异常。shutil.copystat
我试图直接使用shutil.copyfile
,但在这里复制的文件再次随机不存在。添加一些sleep
也无济于事。
在 中shutil.copystat
,当函数尝试访问文件以获取其元数据时引发异常
[L372] lookup("utime")(dst, ns=(st.st_atime_ns, st.st_mtime_ns),
follow_symlinks=follow)
就像声明的那样:
FileNotFoundError: [Errno 2] No such file or directory
../../miniconda3/envs/test_env/lib/python3.8/shutil.py:372: FileNotFoundError
解决方案
推荐阅读
- xamarin.ios - 如何在 MDHTMLLABEL 链接中应用可访问性?
- swift - 如何将 viewModel 类注入 WKInterfaceController?
- regex - 如何设置单元格中的最大字符数并在 Google 表格中达到最大字符数时自动跳过 2 行?
- c# - Microsoft 媒体编码器屏幕截图,保存正在录制的视频的特定部分
- git - 是否可以将 git repo 标记作为变量传递给 ADO 构建管道?
- javascript - AngularJS返回主页的问题
- javascript - Youtube 剪辑自动播放并在按下时从头开始
- amazon-web-services - 为什么我收到 ClusterNotFoundException The referenced cluster is inactive?
- c# - 阻止特定 c# winforms 的桌面共享或检测桌面共享
- python - 如何检查作者是否在 x 服务器中具有 x 角色?