IOError: [Errno 0] Error on write() in tee.TeeInput._tee

未关闭
#139 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

受影响的代码位于 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

benoitc/restkit 的其他 Issue

查看 benoitc/restkit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。