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

Aperta
#139 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Il codice interessato si trova in tee.py intorno alla riga 154; inizia leggendo TeeInput._tee e il flusso di lettura/scrittura di TemporaryFile. Esegui la riproduzione unittest fornita con un file HTML più grande di 45 KB, quindi conferma che le operazioni ripetute di readline e flush non generino più IOError con Errno 0.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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()
Lingua principale
Python
Stelle
402
Fork
69
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di benoitc/restkit

Tutte le issue di benoitc/restkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.