[issue43260] Never release buffer when MemoryError in print()

Inada Naoki report at bugs.python.org
Fri Feb 19 19:57:34 EST 2021


Inada Naoki <songofacandy at gmail.com> added the comment:

This is not the problem only in the optimization. _textiowrapper_writeflush need to create buffer bytes object anyway and if it cause MemoryError, the TextIOWrapper can not flush internal buffer forever.

  stdout.write("small text")
  stdout.write("very large text")  # Calls writeflush, but can not allocate buffer.

This example would stuck on same situation without the optimization.


But the optimization made the problem easy to happen. Now the problem happend with only one learge text.

Idea to fix this problem:

* If input text is large (>1M?)
  * Flush buffer before adding the large text to the buffer.
  * Encode the text and write it to self->buffer soon. Do not put it into internal buffer (self->pending_bytes).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43260>
_______________________________________


More information about the Python-bugs-list mailing list