IOError: [Errno 0] Error on write() in tee.TeeInput._tee
还没有人认领这个 Issue。
评估
调研方向
受影响的代码位于 tee.py 第 154 行附近;先阅读 TeeInput._tee 以及 TemporaryFile 的读写流程。使用一个大于 45 KB 的 HTML 文件运行提供的 unittest 复现,然后确认重复的 readline 和 flush 操作不再引发带有 Errno 0 的 IOError。
由索引模型根据 Issue 内容生成。
描述
In very rare circumstances, the write() on the TemporaryFile files with an IOError, but no error code. I tracked the bug down to the following: When using a file object with read and write mode, then you have to flush or seek, when switching between reading and writing (see http://bugs.python.org/issue3207).
To fix this here, simply reset the filestream pointer by seeking to the position returned by tell(). More specifically, in tee.py:154 add self.tmp.seek(self.tmp.tell()).
If you want to reproduce the error yourself, use the following script. The html file needs to be bigger than two chunk sizes (32KB), so a file with 45 KB should do the trick.
import unittest
from restkit.tee import TeeInput
import os
import tempfile
class TempfileErrorCase(unittest.TestCase):
def test_ioerror(self):
with open("/path/to/large/html/file", "rb") as f:
i = TeeInput(f)
for _ in range(200):
i.readline()
i.tmp.flush()
def tearDown(self):
os.remove(self.tmpfile.name)
# Guard importing as main module
if __name__ == "__main__":
unittest.main()
- 主要语言
- Python
- 星标
- 402
- 派生
- 69
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
benoitc/restkit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 35/100
-
难度 2/5 1-3 小时 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
Bug
难度 4/5 3-5 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 35/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
openvinotoolkit/openvino_notebooks#3858 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 88/100
hummingbot/hummingbot-api#256 ·
-
bug
难度 2/5 1-3 小时 新手友好度 80/100
-
area:other help wanted
难度 2/5 1-3 小时 新手友好度 70/100
WingedGuardian/GENesis-AGI#4734 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
peach-mitao/peach#693 ·
维护者通常 1 天内回复