-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Comments
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:
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. |
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? |
Python 2.7.15 now requires to set PYTHONSHOWREFCOUNT env var to dump "[xxx refs]". |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: