Python Imaging Library (Fork)
Go to file
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
.azure-pipelines/jobs Add Docker builds to Azure Pipelines 2019-02-24 18:00:23 +02:00
.github Turn fail-fast off, so one failed job doesn't cancel others 2019-10-12 12:14:49 +03:00
.travis Split script.sh into build.sh and test.sh 2019-10-12 10:49:26 +03:00
depends Updated libimagequant to 2.12.5 2019-07-29 19:32:12 +10:00
docs Improve handling of file resources 2019-10-12 08:27:17 -07:00
src Improve handling of file resources 2019-10-12 08:27:17 -07:00
Tests Improve handling of file resources 2019-10-12 08:27:17 -07:00
winbuild Merge branch 'master' into gha-win 2019-10-11 19:24:48 +03:00
.appveyor.yml Stop testing Python 2.7 2019-10-11 19:05:20 +03:00
.codecov.yml Add Codecov token to config 2019-10-12 10:49:26 +03:00
.coveragerc Don't exclude Windows code 2014-07-05 21:32:09 +03:00
.editorconfig Remove duplicate line [CI skip] 2016-09-03 12:37:47 +03:00
.gitattributes Set EPS test files as binary 2018-12-29 21:53:07 -08:00
.gitignore Add documentation to Image module 2019-04-06 13:42:22 -07:00
.readthedocs.yml Install project using pip in ReadTheDocs build 2018-10-24 19:46:43 +11:00
.travis.yml Split script.sh into build.sh and test.sh 2019-10-12 10:49:26 +03:00
azure-pipelines.yml Added Debian Buster 2019-07-10 06:54:54 +10:00
CHANGES.rst Updated CHANGES.rst [ci skip] 2019-10-07 13:07:36 +11:00
LICENSE Updated copyright year 2019-01-03 09:32:05 +11:00
Makefile Update Python 2 doc URLs to Python 3 2018-06-09 21:04:34 -07:00
MANIFEST.in Remove empty, unused directory docs/_static 2019-07-06 16:37:57 -07:00
mp_compile.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
README.rst Added GitHub Actions badges [ci skip] 2019-10-11 22:04:21 +11:00
RELEASING.md Do not download dev wheels [ci skip] 2019-10-01 20:27:20 +10:00
requirements.txt Remove unnecessary depedencies of dependencies 2019-07-27 16:35:52 +03:00
selftest.py Improve handling of file resources 2019-10-12 08:27:17 -07:00
setup.cfg Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
setup.py Fix for Python 3.10 2019-08-18 12:32:23 +03:00
tox.ini Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00

Pillow
======

Python Imaging Library (Fork)
-----------------------------

Pillow is the friendly PIL fork by `Alex Clark and Contributors <https://github.com/python-pillow/Pillow/graphs/contributors>`_. PIL is the Python Imaging Library by Fredrik Lundh and Contributors. As of 2019, Pillow development is `supported by Tidelift <https://tidelift.com/subscription/pkg/pypi-pillow>`_.

.. start-badges

.. list-table::
    :stub-columns: 1

    * - docs
      - |docs|
    * - tests
      - |linux| |macos| |windows| |gha_lint| |gha_docker| |coverage|
    * - package
      - |zenodo| |tidelift| |version| |downloads|
    * - social
      - |gitter| |twitter|

.. end-badges

More Information
----------------

- `Documentation <https://pillow.readthedocs.io/>`_

  - `Installation <https://pillow.readthedocs.io/en/latest/installation.html>`_
  - `Handbook <https://pillow.readthedocs.io/en/latest/handbook/index.html>`_

- `Contribute <https://github.com/python-pillow/Pillow/blob/master/.github/CONTRIBUTING.md>`_

  - `Issues <https://github.com/python-pillow/Pillow/issues>`_
  - `Pull requests <https://github.com/python-pillow/Pillow/pulls>`_

- `Changelog <https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst>`_

  - `Pre-fork <https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst#pre-fork>`_

Report a Vulnerability
----------------------

To report a security vulnerability, please follow the procedure described in the `Tidelift security policy <https://tidelift.com/docs/security>`_.

.. |docs| image:: https://readthedocs.org/projects/pillow/badge/?version=latest
   :target: https://pillow.readthedocs.io/?badge=latest
   :alt: Documentation Status

.. |linux| image:: https://img.shields.io/travis/python-pillow/Pillow/master.svg?label=Linux%20build
   :target: https://travis-ci.org/python-pillow/Pillow
   :alt: Travis CI build status (Linux)

.. |macos| image:: https://img.shields.io/travis/python-pillow/pillow-wheels/master.svg?label=macOS%20build
   :target: https://travis-ci.org/python-pillow/pillow-wheels
   :alt: Travis CI build status (macOS)

.. |windows| image:: https://img.shields.io/appveyor/ci/python-pillow/Pillow/master.svg?label=Windows%20build
   :target: https://ci.appveyor.com/project/python-pillow/Pillow
   :alt: AppVeyor CI build status (Windows)

.. |gha_lint| image:: https://github.com/python-pillow/Pillow/workflows/Lint/badge.svg
   :alt: GitHub Actions build status (Lint)

.. |gha_docker| image:: https://github.com/python-pillow/Pillow/workflows/Test%20Docker/badge.svg
   :alt: GitHub Actions build status (Test Docker)

.. |coverage| image:: https://codecov.io/gh/python-pillow/Pillow/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/python-pillow/Pillow
   :alt: Code coverage

.. |zenodo| image:: https://zenodo.org/badge/17549/python-pillow/Pillow.svg
   :target: https://zenodo.org/badge/latestdoi/17549/python-pillow/Pillow

.. |tidelift| image:: https://tidelift.com/badges/package/pypi/Pillow?style=flat
   :target: https://tidelift.com/subscription/pkg/pypi-pillow?utm_source=pypi-pillow&utm_medium=referral&utm_campaign=readme

.. |version| image:: https://img.shields.io/pypi/v/pillow.svg
   :target: https://pypi.org/project/Pillow/
   :alt: Latest PyPI version

.. |downloads| image:: https://img.shields.io/pypi/dm/pillow.svg
   :target: https://pypi.org/project/Pillow/
   :alt: Number of PyPI downloads

.. |gitter| image:: https://badges.gitter.im/python-pillow/Pillow.svg
   :target: https://gitter.im/python-pillow/Pillow?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
   :alt: Join the chat at https://gitter.im/python-pillow/Pillow

.. |twitter| image:: https://img.shields.io/badge/tweet-on%20Twitter-00aced.svg
   :target: https://twitter.com/PythonPillow
   :alt: Follow on https://twitter.com/PythonPillow