小编Lin*_*inf的帖子

python tarfile 将 tar 写入管道

我想创建一个 tar 文件并将其通过管道传输到 http 上传。

然而,似乎 python tarfile 模块执行查找,这使得无法通过管道传输到下一个进程。

这是代码

tar = tarfile.open('named_pipe', mode='w')
tar.add('file1')
p.close()
Run Code Online (Sandbox Code Playgroud)

'named_pipe' 是由 mkfifo 命令创建的命名管道文件,当我运行它并在另一个终端中 cat 命名管道时,出现错误

tar = tarfile.open('named_pipe', mode='w')
  File "/usr/lib/python2.7/tarfile.py", line 1695, in open
    return cls.taropen(name, mode, fileobj, **kwargs)
  File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
    return cls(name, mode, fileobj, **kwargs)
  File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
    self.offset = self.fileobj.tell()
IOError: [Errno 29] Illegal seek
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

python pipe tarfile

5
推荐指数
1
解决办法
1212
查看次数

标签 统计

pipe ×1

python ×1

tarfile ×1