79391712

Date: 2025-01-27 17:56:32
Score: 0.5
Natty:
Report link

It turns out there are two reasons for this, both stemming from the same piece of code in ImageFile.py

if self._exclusive_fp and self._close_exclusive_fp_after_loading:
    self.fp.close()
self.fp = None

If a file path is passed into Image.open() then it will be closed, but even if a file is opened explicitly it will be closed by the garbage collector after self.fp is assigned to None.

The solution takes three changes:

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: MarshalH