Navigation Menu

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

[2.7] Add PYTHONSHOWREFCOUNT environment variable to Python 2.7 #75914

Closed
vstinner opened this issue Oct 9, 2017 · 5 comments
Closed

[2.7] Add PYTHONSHOWREFCOUNT environment variable to Python 2.7 #75914

vstinner opened this issue Oct 9, 2017 · 5 comments

Comments

@vstinner
Copy link
Member

vstinner commented Oct 9, 2017

BPO 31733
Nosy @vstinner, @benjaminp, @ezio-melotti, @serhiy-storchaka, @stratakis
PRs
  • [2.7] bpo-31733: Add PYTHONSHOWREFCOUNT env var #3932
  • [2.7] bpo-31733, bpo-31692: Document 2 new env vars in What's New in Python 2.7 #4019
  • 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 2017-10-17.10:03:43.361>
    created_at = <Date 2017-10-09.13:44:19.479>
    labels = []
    title = '[2.7] Add PYTHONSHOWREFCOUNT environment variable to Python 2.7'
    updated_at = <Date 2017-10-17.20:13:15.247>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2017-10-17.20:13:15.247>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-10-17.10:03:43.361>
    closer = 'vstinner'
    components = []
    creation = <Date 2017-10-09.13:44:19.479>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31733
    keywords = ['patch']
    message_count = 5.0
    messages = ['303952', '303962', '304491', '304496', '304526']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'benjamin.peterson', 'ezio.melotti', 'serhiy.storchaka', 'cstratak']
    pr_nums = ['3932', '4019']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue31733'
    versions = ['Python 2.7']

    @vstinner
    Copy link
    Member Author

    vstinner commented Oct 9, 2017

    When Python 2.7 is built in debug mode, it displays the total number of references when the program finishes or after each statement in the interactive interpreter.

    Example:

    haypo@selma$ ./python
    Python 2.7.14+ (heads/2.7:cc4b6f1c62, Oct  9 2017, 15:30:11) 
    [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1+1
    2
    [45025 refs]
    >>> 2+2
    4
    [45025 refs]
    >>> 
    [45025 refs]
    [21655 refs]

    While I'm Python core developer working on reference leaks for years, I *never* used this value. I only use "python -m test -R 3:3 test_xxx" to track reference leaks.

    I really liked Python 3.4 which made this option an opt-in, python3 -X showrefcount: bpo-17323 (commit 1f8898a).

    I propose to change Python 2.7 behaviour to not print this value by default, but add a new PYTHONSHOWREFCOUNT environment variable to display it. The value is displayed if PYTHONSHOWREFCOUNT is set. Other similar existing variables:

    • PYTHONTHREADDEBUG
    • PYTHONDUMPREFS
    • PYTHONMALLOCSTATS

    https://docs.python.org/2.7/using/cmdline.html#debug-mode-variables

    I prefer to add a new environment style rather than adding a new -X command line option. IMHO an environment variable is less intrusive. For example, older Python 2.7 versions completely ignore unknown environment variables, whereas "python2.7 -X showrefcount ..." currently logs the "-X is reserved for implementation-specific arguments" message into stderr.

    Attached PR adds PYTHONSHOWREFCOUNT.

    @vstinner
    Copy link
    Member Author

    vstinner commented Oct 9, 2017

    Since this issue is on the thin border between "feature" and "bug fix", I would like to get the feedback of Benjamin on this change.

    @benjamin: Are you ok to make such change late in the Python 2.7 cycle, in Python 2.7.15?

    @vstinner
    Copy link
    Member Author

    New changeset 3c082a7 by Victor Stinner in branch '2.7':
    bpo-31733: Add PYTHONSHOWREFCOUNT env var (GH-3932)
    3c082a7

    @vstinner
    Copy link
    Member Author

    Python 2.7.15 now requires to set PYTHONSHOWREFCOUNT env var to dump "[xxx refs]".

    @vstinner
    Copy link
    Member Author

    New changeset 355393e by Victor Stinner in branch '2.7':
    [2.7] bpo-31733, bpo-31692: Document 2 new env vars in What's New in Python 2.7 (GH-4019)
    355393e

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant