Who use PYTHONDUMPREFS env var and combinerefs.py script?


I’m working on removing outdated example scripts in Tools/scripts/ and I found a combinerefs.py script in Tools/scripts/. I used PYTHONDUMPREFS a few days, but I wasn’t aware of this script (!) and I was never able to extract anything useful from this very verbose output. Usually, I found my issues with bisection, reading source code and tools others than “trace refs”.

Since Python 3.8, Python built in debug mode no longer defines the Py_TRACE_REFS macro which adds the double linked list to PyObject. It’s now a configure option (./configure --with-trace-refs).

I’m now curious if someone still uses the PYTHONDUMPREFS env var and can get anything useful from this output? In this case, please tell me, it may help me :slight_smile:

At least, sys.getobjects() (also enabled by Py_TRACE_REFS macro) still looks interesting to debug, since it contains Python objects not tracked by the GC (not listed by gc.get_objects()).

For me, the main question is: would you be ok with removing Tools/scripts/combinerefs.py?

Should we even deprecate and/or remove PYTHONDUMPREFS env var? I’m fine with keeping it if someone finds it useful.

The “Trace refs” debug feature is currently documented at: 3. Configure Python — Python 3.12.0a0 documentation (yep, the doc is very short…). There is a “Trace Refs” buildbot making sure that it’s still possible to build Python with this debug option :wink:


You’d have to ask Tim Peters, who wrote the script. :slight_smile: But I’m sure he’s okay with letting go of it, he’s moved on to other topics.

I’m also okay, plus the script is already preserved in my old-demos repo.

cc @tim.one

Maybe PYTHONDUMPREFS and PYTHONDUMPREFSFILE environment variables should just be removed if no one is using them. There are now plently of ways to detect memory leaks in Python, and Python 3.12 is now way better to release memory at exit: Mailman 3 Python no longer leaks memory at exit - Python-Dev - python.org