serhiy-storchaka · GitHub

Bug report

The following code

from _pyio import BytesIO
memio = BytesIO(b"1234567890")
buf = memio.getbuffer()
del memio

raises an unraisable exception:

Exception ignored in: <function IOBase.__del__ at 0x7f390c69b410>
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/_pyio.py", line 418, in __del__
    self.close()
  File "/home/serhiy/py/cpython/Lib/_pyio.py", line 907, in close
    self._buffer.clear()
BufferError: Existing exports of data: object cannot be re-sized

Deleting a reference to object while there is still a live buffer that refers its content should not be an issue. It is not an abnormal situation and it should not produce any output.

It is only for the Python implementation. The C implementation raises an unraisable exception in different situation. See #111331.

Linked PRs

Read the original on github.com ↗