繁体   English   中英

pysftp + py7zr 解压缩挂在存档上

[英]pysftp + py7zr decompress is hanging on archive

一点上下文:客户端将 7-zip 存档放在远程 sftp 服务器上,我处理它们。

我的问题是,在某些 7-zip 文件上,我的程序挂起,解压缩 function 永无止境,但存档的所有文件都在本地服务器上找到(存在)。

我设法在终端上通过 ctrl+c 获得堆栈跟踪:

[终端画面][1][1]:https://i.stack.imgur.com/O62U4.png

我的代码:

    def download_from_sftp(self):
    with pysftp.Connection(host=self.hostname, port=self.port, username=self.user, password=self.password, cnopts=self.cnopts) as sftp:
        self.logger.debug("Connection succesfully established ... ")

        sftp.cwd(self.path)  # Switch to a remote directory

        directory_structure = sftp.listdir_attr()

        self.logger.debug("Downloading zip files :")
        for attr in directory_structure:
            self.logger.debug(attr.filename + " " + str(attr))
            sftp.get(attr.filename, self.path_retour + attr.filename)

            with py7zr.SevenZipFile(self.path_retour + attr.filename, mode='r') as z:
                z.extractall(self.path_retour)

            os.rename(self.path_retour + attr.filename, self.path_archive_python + attr.filename)  # move zip to archive folder on local server
            sftp.remove(attr.filename)  # delete zip on remote server

对于 1000 个 7zip 存档(大多数存档小于 1mb),此问题可能会发生 1 次。 我试图验证档案的完整性并且它们是有效的。 在我的桌面上,py7zr 能够提取档案的所有文件而不会崩溃/挂起。

我在想也许是 sftp 连接导致挂起。

谢谢

- - 编辑 - -

根据 MartinPrikryl 的反馈,我确实在本地计算机上运行了我的整个脚本并且它没有挂起。 它仅与运行脚本的服务器一起挂起该特定存档。 我注意到存档比另一个大得多(~ 9mb)。 但是服务器有很多磁盘空间(1 TB 可用)、4gb 内存和 4 个 CPU,所以这应该不是问题。

我没能找到为什么 py7zr 挂在一些档案上,但是将 python 3.7.4 更新到 python 3.8.5解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM