Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print warning at shutdown if gc.garbage not empty #35458

Closed
tim-one opened this issue Nov 3, 2001 · 10 comments
Closed

Print warning at shutdown if gc.garbage not empty #35458

tim-one opened this issue Nov 3, 2001 · 10 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@tim-one
Copy link
Member

tim-one commented Nov 3, 2001

BPO 477863
Nosy @gvanrossum, @tim-one, @ncoghlan, @pitrou, @florentx
Files
  • gc_fini.patch
  • gc_fini2.patch
  • gc_fini3.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-08-08.22:21:45.568>
    created_at = <Date 2001-11-03.20:07:42.000>
    labels = ['interpreter-core', 'type-feature']
    title = 'Print warning at shutdown if gc.garbage not empty'
    updated_at = <Date 2010-08-08.22:21:45.567>
    user = 'https://github.com/tim-one'

    bugs.python.org fields:

    activity = <Date 2010-08-08.22:21:45.567>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-08-08.22:21:45.568>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2001-11-03.20:07:42.000>
    creator = 'tim.peters'
    dependencies = []
    files = ['18378', '18379', '18394']
    hgrepos = []
    issue_num = 477863
    keywords = ['patch']
    message_count = 10.0
    messages = ['61071', '77936', '112783', '112788', '112793', '112795', '112898', '112915', '112920', '113343']
    nosy_count = 5.0
    nosy_names = ['gvanrossum', 'tim.peters', 'ncoghlan', 'pitrou', 'flox']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue477863'
    versions = ['Python 3.2']

    @tim-one
    Copy link
    Member Author

    tim-one commented Nov 3, 2001

    Here are comments from Guido, taken from a patch
    report that's been closed:

    """
    In a discussion before lunch, Tim suggested that when
    Python exits (or better, in Py_Finalize()) a check
    could be made if there is any garbage in gc.garbage,
    and if so, a warning about this should be printed to
    stderr. That seems a nice feature.

    In that same discussion, I realized that the module
    cleanup behavior (where all globals in a module are
    set to None when the module object is deallocated) is
    probably no longer necessary now that we have GC.
    """

    The point to #1 is that we let objects in unreachable
    cycles leak when they have __del__ methods. While we
    give the user ways to know about that and to clean
    them up (via exposing the trash in gc.garbage), a non-
    expert user (or an expert who simply isn't thinking
    about this -- whatever, you don't know unless you
    specifically look for it) may never know that they're
    leaking.

    @tim-one tim-one added type-feature A feature request or enhancement labels Nov 3, 2001
    @pitrou
    Copy link
    Member

    pitrou commented Dec 16, 2008

    Although this dates back to 2001, I think this might still be useful.

    @pitrou pitrou added interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Dec 16, 2008
    @pitrou pitrou changed the title New gc work Print warning at shutdown if gc.garbage not empty Mar 17, 2010
    @pitrou pitrou changed the title New gc work Print warning at shutdown if gc.garbage not empty Mar 17, 2010
    @pitrou
    Copy link
    Member

    pitrou commented Aug 4, 2010

    Displaying the full list may be unwieldy if it's very large. Instead, we could by default display the following kind of message:

    Python warning: 5 uncollectable objects remaining at interpreter shutdown. Use gc.DEBUG_UNCOLLECTABLE to list them.

    And list gc.garbage only if gc.DEBUG_UNCOLLECTABLE is defined.

    @pitrou
    Copy link
    Member

    pitrou commented Aug 4, 2010

    Here is a patch. Perhaps I should add tests too.

    @pitrou
    Copy link
    Member

    pitrou commented Aug 4, 2010

    New patch with tests.

    @pitrou
    Copy link
    Member

    pitrou commented Aug 4, 2010

    More thorough tests.

    @ncoghlan
    Copy link
    Contributor

    ncoghlan commented Aug 4, 2010

    Patch looks basically OK on an eyeball scan. A couple of suggestions:

    • use test.script_helper.run_python rather than rolling your own run_command (or, at least, just make run_command a thin wrapper around run_python). I've been trying to trim down the number of different ways the test suite launches interpreter subprocesses for testing purposes, and script_helper also does a bit of extra cleanup to try to eliminate false alarms regarding reference leaks. That said, I do like the way you're checking that the output went to the correct stream, so perhaps instead add a run_python variant to script_helper that returns a 3-tuple containing the exit code, stdout and stderr and make your run_command a wrapper around that (then create an issue to migrate the rest of the script_helper.run_python based tests to switch to the new version so they will also check that the output is on the correct stream rather than lumping the two streams together).

    • update the description of gc.DEBUG_UNCOLLECTABLE in the docs to specifically mention that the complete list of uncollectable objects will also be printed at interpreter shutdown.

    @pitrou
    Copy link
    Member

    pitrou commented Aug 4, 2010

    • use test.script_helper.run_python rather than rolling your own
      run_command (or, at least, just make run_command a thin wrapper around
      run_python). I've been trying to trim down the number of different
      ways the test suite launches interpreter subprocesses for testing
      purposes, and script_helper also does a bit of extra cleanup to try to
      eliminate false alarms regarding reference leaks.

    After a quick grep, it seems script_helper is really in the minority
    (it's only used in three test files) while ad hoc calls to subprocess
    with sys.executable are all over the place. I'd rather open a separate
    feature request for that new script_helper function than convert all
    uses of subprocess in this issue.

    • update the description of gc.DEBUG_UNCOLLECTABLE in the docs to
      specifically mention that the complete list of uncollectable objects
      will also be printed at interpreter shutdown.

    Ah, indeed. Thanks!

    @pitrou
    Copy link
    Member

    pitrou commented Aug 4, 2010

    Here is a new patch with doc.

    @pitrou
    Copy link
    Member

    pitrou commented Aug 8, 2010

    I went forward and committed the patch in r83861.

    @pitrou pitrou closed this as completed Aug 8, 2010
    @pitrou pitrou closed this as completed Aug 8, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants