Skip to content

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

Description

@pszalanski

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions