Python 2.0

Michael Hudson mwh21 at
Tue Jun 1 18:00:35 CEST 1999

On Tue, 1 Jun 1999, Stidolph, David wrote:
> Py_TRACE_REFS seems to be defined if Py_DEBUG is defined.
> I cannot find a "getobjects" or any other similar function in the source
> code or docs.  I am using the Win32 version 1.5.2.

Well, Python/sysmodule.c in the source contains this:

static PyMethodDef sys_methods[] = {
        /* Might as well keep this in alphabetic order */
        {"exc_info",    sys_exc_info, 0, exc_info_doc},
        {"exit",        sys_exit, 0, exit_doc},
        {"getcounts",   sys_getcounts, 0},
        {"getdxp",      _Py_GetDXProfile, 1},
#ifdef Py_TRACE_REFS
        {"getobjects",  _Py_GetObjects, 1},
        {"getrefcount", sys_getrefcount, 0, getrefcount_doc},
        {"mdebug",      sys_mdebug, 0},
        {"setcheckinterval",    sys_setcheckinterval, 1,
        {"setprofile",  sys_setprofile, 0, setprofile_doc},
        {"settrace",    sys_settrace, 0, settrace_doc},
        {NULL,          NULL}           /* sentinel */

and this:

#ifdef Py_TRACE_REFS
/* Defined in objects.c because it uses static globals if that file */
extern PyObject *_Py_GetObjects Py_PROTO((PyObject *, PyObject *));

and Objects/object.c contains:
PyObject *
_Py_GetObjects(self, args)
        PyObject *self;
        PyObject *args;

This is all on Linux, but the source is the source, as I understand it. I
mean the C source, not the Python Library source... I'd hoped that was

I doubt it is documented anywhere - a quick grep through the docs finds
nowt, though Doc/api/api.tex contains the line:


I'd heard about it sometime on the newsgroup.

> Any help would be appreciated,

If this is what you were looking for, you're welcome.


> David Stidolph.
> -----Original Message-----
> From: Michael Hudson [mailto:mwh21 at]
> Sent: Tuesday, June 01, 1999 4:55 AM
> To: python-list at
> Subject: Re: Python 2.0
> "Stidolph, David" <stidolph at> writes:
> > >OK, I'll try to propose something constructive. Maybe we need an object
> > >protocol, that would enumerate
> > >all references held by an object ?  Writing a portable GC would be then
> > much
> > >easier.
> > 
> > Sounds good to me for debugging.  A call that could return a list of
> > everything that holds a reference to an object - that would be cool!
> > 
> > list = GetReferences(object)
> > print 'List of referencest to',object
> > for item in list:
> >   print 'item:',item
> > 
> > Anybody know of a current way to do this?
> If you recompile Python with Py_TRACE_REFS defined, then the sys
> module sprouts a "getobjects" function that returns a list of all
> objects in existence. This could probably be used to implement
> something like this. It would be veeeeery slow, I suspect.
> I've never resorted to this approach, tending always to make cyclic
> references go away be staring at them very, very hard.
> I'm not sure this is at all what is being asked for, but it seems kind
> of relavent.
> Yours,
> Michael

More information about the Python-list mailing list