Pillow/docs
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
..
example Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
handbook Improve handling of file resources 2019-10-12 08:27:17 -07:00
reference Improve handling of file resources 2019-10-12 08:27:17 -07:00
releasenotes Use double backticks [ci skip] 2019-10-06 14:39:10 +11:00
resources/js Fixed JS errors in local Sphinx build 2019-01-19 20:39:13 +11:00
about.rst add last PIL release version and date to about.rst 2018-07-01 09:39:26 +03:00
conf.py Introduce isort to automate import ordering and formatting (#3954) 2019-07-16 23:02:31 +03:00
COPYING Updated copyright year 2019-01-03 09:32:05 +11:00
deprecations.rst Merge branch 'master' into rm-deprecated-qt 2019-10-06 13:35:38 +11:00
Guardfile Introduce isort to automate import ordering and formatting (#3954) 2019-07-16 23:02:31 +03:00
index.rst Added Tidelift Subscription link [ci skip] 2019-09-05 19:31:55 +10:00
installation.rst Merge pull request #3993 from radarhere/libimagequant 2019-08-17 20:02:12 +10:00
make.bat Fresh start for docs, generated by sphinx-apidoc 2013-04-12 19:52:50 +02:00
Makefile Clean up Handbook 2015-09-30 06:38:51 -04:00
PIL.rst Remove redundant module skipping 2018-07-14 23:33:54 +03:00
porting.rst Port to the top 2015-09-30 07:28:35 -04:00