cpython: 7f3695701724 (original) (raw)

Mercurial > cpython

changeset 93770:7f3695701724

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

Antoine Pitrou solipsis@pitrou.net
date Sun, 07 Dec 2014 01:28:27 +0100
parents 628acf7dbc8d
children ee095a2e2b35
files Doc/glossary.rst Doc/library/gc.rst Doc/library/sys.rst Doc/library/weakref.rst Lib/test/test_sys.py Misc/NEWS Python/sysmodule.c
diffstat 7 files changed, 62 insertions(+), 6 deletions(-)[+] [-] Doc/glossary.rst 13 Doc/library/gc.rst 6 Doc/library/sys.rst 8 Doc/library/weakref.rst 6 Lib/test/test_sys.py 21 Misc/NEWS 3 Python/sysmodule.c 11

line wrap: on

line diff

--- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -402,6 +402,19 @@ Glossary than compiled ones, though their programs generally also run more slowly. See also :term:interactive.

+

+ iterable An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as :class:list, :class:str,

--- a/Doc/library/gc.rst +++ b/Doc/library/gc.rst @@ -186,7 +186,7 @@ values but should not rebind them): added to this list rather than freed. .. versionchanged:: 3.2

@@ -252,8 +252,8 @@ The following constants are provided for to the garbage list. .. versionchanged:: 3.2

.. data:: DEBUG_SAVEALL

--- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -718,6 +718,14 @@ always available. value of :func:intern around to benefit from it. +.. function:: is_finalizing() +

+ .. data:: last_type last_value last_traceback

--- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -258,7 +258,7 @@ These method have the same issues as the are called in reverse order of creation. A finalizer will never invoke its callback during the later part of

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

--- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -744,6 +744,27 @@ class SysModuleTest(unittest.TestCase): c = sys.getallocatedblocks() self.assertIn(c, range(b - 50, b + 50))

+

+

+

+ @test.support.cpython_only class SizeofTest(unittest.TestCase):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -194,6 +194,9 @@ Core and Builtins Library ------- +- Issue #22696: Add function :func:sys.is_finalizing to know about

--- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1121,6 +1121,16 @@ PyDoc_STRVAR(sys_clear_type_cache__doc__ "_clear_type_cache() -> None\n[](#l7.4) Clear the internal type lookup cache."); +static PyObject +sys_is_finalizing(PyObject self, PyObject* args) +{

+} + +PyDoc_STRVAR(is_finalizing_doc, +"is_finalizing()\n[](#l7.14) +Return True if Python is exiting."); + static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order / @@ -1167,6 +1177,7 @@ static PyMethodDef sys_methods[] = { getwindowsversion_doc}, #endif / MS_WINDOWS */ {"intern", sys_intern, METH_VARARGS, intern_doc},

#ifdef USE_MALLOPT {"mdebug", sys_mdebug, METH_VARARGS}, #endif