Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pszalanski opened this issue Dec 9, 2014 · 0 comments
Open

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

pszalanski opened this issue Dec 9, 2014 · 0 comments

Comments

@pszalanski
Copy link

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant