gpt4 book ai didi

python-3.x - shutdown.copystat() 在 Azure 上的 Docker 内部失败

转载 作者:行者123 更新时间:2023-12-02 11:32:47 25 4
gpt4 key购买 nike

失败的代码在基于 python:3.6-stretch debian 的 Docker 容器内运行。当 Django 将文件从一个 Docker 卷移动到另一个 Docker 卷时,就会发生这种情况。

当我在 MacOS 10 上测试时,它工作正常,没有错误。此处,Docker 容器通过 docker-compose 启动,并使用本地计算机上的常规 Docker 卷。

部署到 Azure(AKS - Azure 上的 Kubernetes)中,移动文件成功,但复制统计信息失败,并出现以下错误:

  File "/usr/local/lib/python3.6/site-packages/django/core/files/move.py", line 70, in file_move_safe
copystat(old_file_name, new_file_name)
File "/usr/local/lib/python3.6/shutil.py", line 225, in copystat
_copyxattr(src, dst, follow_symlinks=follow)
File "/usr/local/lib/python3.6/shutil.py", line 157, in _copyxattr
names = os.listxattr(src, follow_symlinks=follow_symlinks)
OSError: [Errno 38] Function not implemented: '/some/path/file.pdf'

Azure 上的卷是具有 ReadWriteMany 访问模式的持久卷声明。

现在,copystat 记录为:

copystat() never returns failure.

https://docs.python.org/3/library/shutil.html

我的问题是:

  • 这是一个“错误”吗,因为文档说它应该“永不返回失败”?
  • 我可以尝试/排除此错误吗,因为相关文件已被移动(仅在稍后尝试复制统计信息时才会失败)
  • 我可以更改 Azure 设置来解决此问题吗? (可能不是)

这里是在 Azure 本身的机器上进行的一些小测试:

root:/media/documents# ls -al
insgesamt 267
drwxrwxrwx 2 1000 1000 0 Jul 31 15:29 .
drwxrwxrwx 2 1000 1000 0 Jul 31 15:29 ..
-rwxrwxrwx 1 1000 1000 136479 Jul 31 16:48 orig.pdf
-rwxrwxrwx 1 1000 1000 136479 Jul 31 15:29 testfile
root:/media/documents# lsattr
--S-----c-jI------- ./orig.pdf
--S-----c-jI------- ./testfile
root:/media/documents# python
Python 3.6.6 (default, Jul 17 2018, 11:12:33)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.copystat('orig.pdf', 'testfile')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/shutil.py", line 225, in copystat
_copyxattr(src, dst, follow_symlinks=follow)
File "/usr/local/lib/python3.6/shutil.py", line 157, in _copyxattr
names = os.listxattr(src, follow_symlinks=follow_symlinks)
OSError: [Errno 38] Function not implemented: 'orig.pdf'
>>> shutil.copystat('orig.pdf', 'testfile', follow_symlinks=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/shutil.py", line 225, in copystat
_copyxattr(src, dst, follow_symlinks=follow)
File "/usr/local/lib/python3.6/shutil.py", line 157, in _copyxattr
names = os.listxattr(src, follow_symlinks=follow_symlinks)
OSError: [Errno 38] Function not implemented: 'orig.pdf'
>>>

最佳答案

以下解决方案是一个修补程序。它必须应用于直接或间接调用copystat任何方法(或任何产生可忽略的errno.ENOSYS的shutil方法)。

if hasattr(os, 'listxattr'):
LOGGER.warning('patching listxattr to avoid ERROR 38 (errno.ENOSYS)')
# avoid "ERROR 38 function not implemented on Azure"
with mock.patch('os.listxattr', return_value=[]):
file_field.save(name=name, content=GeneratedFile(fresh, content_type=content_type), save=True)
else:
file_field.save(name=name, content=GeneratedFile(fresh, content_type=content_type), save=True)

file_field.save 是调用相关 shutil 代码的 Django 方法。这是我的代码中出现错误之前的最后一个位置。

关于python-3.x - shutdown.copystat() 在 Azure 上的 Docker 内部失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51616058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com