Pillow/src
Jon Dufresne 4cd4adddc3 Improve handling of file resources
Follow Python's file object semantics. User code is responsible for
closing resources (usually through a context manager) in a deterministic
way.

To achieve this, remove __del__ functions. These functions used to
closed open file handlers in an attempt to silence Python
ResourceWarnings. However, using __del__ has the following drawbacks:

- __del__ isn't called until the object's reference count reaches 0.
  Therefore, resource handlers remain open or in use longer than
  necessary.

- The __del__ method isn't guaranteed to execute on system exit. See the
  Python documentation:

  https://docs.python.org/3/reference/datamodel.html#object.__del__

  > It is not guaranteed that __del__() methods are called for objects
  > that still exist when the interpreter exits.

- Exceptions that occur inside __del__ are ignored instead of raised.
  This has the potential of hiding bugs. This is also in the Python
  documentation:

  > Warning: Due to the precarious circumstances under which __del__()
  > methods are invoked, exceptions that occur during their execution
  > are ignored, and a warning is printed to sys.stderr instead.

Instead, always close resource handlers when they are no longer in use.
This will close the file handler at a specified point in the user's code
and not wait until the interpreter chooses to. It is always guaranteed
to run. And, if an exception occurs while closing the file handler, the
bug will not be ignored.

Now, when code receives a ResourceWarning, it will highlight an area
that is mishandling resources. It should not simply be silenced, but
fixed by closing resources with a context manager.

All warnings that were emitted during tests have been cleaned up. To
enable warnings, I passed the `-Wa` CLI option to Python. This exposed
some mishandling of resources in ImageFile.__init__() and
SpiderImagePlugin.loadImageSeries(), they too were fixed.
2019-10-12 08:27:17 -07:00
..
libImaging Merge pull request #4104 from radarhere/overrun 2019-09-30 23:33:28 +10:00
PIL Improve handling of file resources 2019-10-12 08:27:17 -07:00
Tk Fixed ImageTk getimage 2019-04-29 23:43:13 +10:00
_imaging.c Removed unused argument 2019-07-04 20:07:33 +10:00
_imagingcms.c Merge branch 'master' into imagecms-deprecations 2019-03-27 12:03:54 +02:00
_imagingft.c Added text stroking 2019-07-29 06:40:03 +10:00
_imagingmath.c source layout reorg 2017-12-28 14:49:47 +00:00
_imagingmorph.c Fixed typo 2018-06-26 22:07:40 +10:00
_imagingtk.c source layout reorg 2017-12-28 14:49:47 +00:00
_webp.c Read/Save RGB webp as RGB (instead of RGBX) 2018-08-09 11:40:10 -07:00
decode.c Use unsigned int to store TIFF IFD offsets 2019-06-27 15:07:52 -07:00
display.c Merge branch 'master' into dpi_fix 2019-09-27 09:11:01 +02:00
encode.c Return after error 2019-07-13 13:50:13 +10:00
map.c Changed overflow check to use PY_SSIZE_T_MAX 2019-07-17 07:07:26 +10:00
outline.c source layout reorg 2017-12-28 14:49:47 +00:00
path.c Fix msvc9 compile error 2019-06-25 17:18:37 -07:00
py3.h source layout reorg 2017-12-28 14:49:47 +00:00