Confusing behavior of selectors with buffered file objects

Aperta
#101,053 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
48/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

Inizia dalla documentazione di selectors e dal comportamento di BufferedIOBase citato nell’issue, quindi confronta esempi che usano sys.stdin e socket.makefile(). Determina se l’ambito riguarda un avviso nella documentazione o il supporto dell’implementazione per i dati bufferizzati. Il lavoro è completato quando il comportamento scelto è documentato chiaramente, inclusa la raccomandazione os.read(fileobj.fileno(), size) se la modifica rimane limitata alla documentazione.

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

Descrizione

docs topic-socket

Using selectors with buffered file objects is confusing because the selector will only report whether there is something to read in the underlying file descriptor and ignore the internal buffer. This is especially relevant because buffered file objects are used in many places in the standard library, e.g. sys.stdin or socket.makefile().

I propose to add a corresponding warning to the docs, e.g. like this:

Selectors only look at the underlying file descriptors, so they do not know about data that is buffered in python code. Buffered file objects are used in many places in the standard library, e.g. sys.stdin or socket.makefile(). In those cases, it is recommended to bypass the buffering by using os.read(fileobj.fileno(), size) instead of fileobj.read(size).

Even better would be add code to handle buffered file objects. Unfortunately, I think that BufferedIOBase does not expose whether it has data in its buffer.

Lingua principale
Python
Stelle
77.2k
Fork
36k
Merge medio
1g 9h
PR unite (30g)
558

Guida per i contributori

Apri la guida per i contributori

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 python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.