This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2017-10-09.13:44:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1507556659.49.0.213398074469.issue31733@psf.upfronthosting.co.za>
In-reply-to
Content
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 1f8898a5916b942c86ee8716c37d2db388e7bf2f).

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.
History
Date User Action Args
2017-10-09 13:44:19vstinnersetrecipients: + vstinner
2017-10-09 13:44:19vstinnersetmessageid: <1507556659.49.0.213398074469.issue31733@psf.upfronthosting.co.za>
2017-10-09 13:44:19vstinnerlinkissue31733 messages
2017-10-09 13:44:19vstinnercreate