Issue #22696: Add function :func:sys.is_finalizing to know about interpreter shutdown.

This commit is contained in:
Antoine Pitrou 2014-12-07 01:28:27 +01:00
parent b9859daeeb
commit 5db1bb81ff
7 changed files with 62 additions and 6 deletions

View file

@ -186,7 +186,7 @@ values but should not rebind them):
added to this list rather than freed.
.. versionchanged:: 3.2
If this list is non-empty at interpreter shutdown, a
If this list is non-empty at :term:`interpreter shutdown`, a
:exc:`ResourceWarning` is emitted, which is silent by default. If
:const:`DEBUG_UNCOLLECTABLE` is set, in addition all uncollectable objects
are printed.
@ -252,8 +252,8 @@ The following constants are provided for use with :func:`set_debug`:
to the ``garbage`` list.
.. versionchanged:: 3.2
Also print the contents of the :data:`garbage` list at interpreter
shutdown, if it isn't empty.
Also print the contents of the :data:`garbage` list at
:term:`interpreter shutdown`, if it isn't empty.
.. data:: DEBUG_SAVEALL

View file

@ -718,6 +718,14 @@ always available.
value of :func:`intern` around to benefit from it.
.. function:: is_finalizing()
Return :const:`True` if the Python interpreter is
:term:`shutting down <interpreter shutdown>`, :const:`False` otherwise.
.. versionadded:: 3.5
.. data:: last_type
last_value
last_traceback

View file

@ -258,7 +258,7 @@ These method have the same issues as the and :meth:`keyrefs` method of
are called in reverse order of creation.
A finalizer will never invoke its callback during the later part of
the interpreter shutdown when module globals are liable to have
the :term:`interpreter shutdown` when module globals are liable to have
been replaced by :const:`None`.
.. method:: __call__()
@ -527,8 +527,8 @@ follows::
Starting with Python 3.4, :meth:`__del__` methods no longer prevent
reference cycles from being garbage collected, and module globals are
no longer forced to :const:`None` during interpreter shutdown. So this
code should work without any issues on CPython.
no longer forced to :const:`None` during :term:`interpreter shutdown`.
So this code should work without any issues on CPython.
However, handling of :meth:`__del__` methods is notoriously implementation
specific, since it depends on internal details of the interpreter's garbage