Pillow/docs/reference
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
..
block_allocator.rst Fixed typo [ci skip] 2019-02-10 12:33:16 +11:00
ExifTags.rst Added docs for previously-undocumented ExifTags module. 2014-07-12 10:44:27 -05:00
Image.rst RST uses double backticks for code (MD uses 1) 2019-09-13 08:56:33 +03:00
ImageChops.rst Added method 2019-01-01 14:11:52 +11:00
ImageCms.rst RST uses double backticks for code (MD uses 1) 2019-09-13 08:56:33 +03:00
ImageColor.rst Added getrgb hsb color string 2018-05-31 06:14:29 +10:00
ImageDraw.rst Added text stroking 2019-07-29 06:40:03 +10:00
ImageEnhance.rst Improved documentation 2017-12-30 21:23:04 +11:00
ImageFile.rst s/lena/hopper/ 2017-03-11 13:50:19 +00:00
ImageFilter.rst Document class members automatically 2019-04-21 23:28:08 +10:00
ImageFont.rst Improved ImageFont documentation 2019-07-25 20:04:45 +10:00
ImageGrab.rst add version added [ci skip] 2019-09-27 00:58:32 +02:00
ImageMath.rst Highlight function [ci skip] 2019-05-08 12:54:12 +10:00
ImageMorph.rst Removed trailing whitespace 2015-10-11 21:24:35 +11:00
ImageOps.rst Updated documentation [ci skip] 2019-10-08 21:12:15 +11:00
ImagePalette.rst Document PIL.ImagePalette as best I can 2013-10-13 21:27:07 -07:00
ImagePath.rst RST uses double backticks for code (MD uses 1) 2019-09-13 08:56:33 +03:00
ImageQt.rst Drop support for EOL PyQt4 and PySide 2019-09-30 17:58:31 +03:00
ImageSequence.rst Document class members automatically 2019-04-21 23:28:08 +10:00
ImageStat.rst Corrected note syntax [ci skip] 2019-08-03 23:24:28 +10:00
ImageTk.rst Fully document PIL.ImageTk 2013-10-13 22:09:02 -07:00
ImageWin.rst Document class members automatically 2019-04-21 23:28:08 +10:00
index.rst Merge pull request #2199 from jdufresne/dep-olefile 2016-12-13 20:12:29 +00:00
internal_design.rst Trim trailing whitespace docs dir 2018-01-27 00:04:46 -06:00
limits.rst Updated limits documentation [ci skip] 2017-06-08 20:21:00 +10:00
open_files.rst Improve handling of file resources 2019-10-12 08:27:17 -07:00
PixelAccess.rst Allow RGBA value for P image putpixel 2018-12-31 13:37:04 +11:00
plugins.rst Removed trailing whitespace 2015-10-11 21:24:35 +11:00
PSDraw.rst Fully document PIL.PSDraw 2013-10-13 22:30:00 -07:00
PyAccess.rst Added documentation for negative index pixel access [ci skip] 2018-11-05 21:30:04 +11:00
TiffTags.rst Fixed typo [ci skip] 2016-12-02 10:27:38 +11:00