Module gets garbage collected; its globals become None

Tim Peters tim_one at email.msn.com
Sat May 24 12:54:51 EDT 2003


Note that, new in 2.3, the garbage collector is called during shutdown, once
before the modules are zapped, and again after.  This cleanly gets rid of
more kinds of cyclic trash than before, and allows more finalizers to get
called.

New PYTHONDUMPREFS debug output was also added, and the new
Tools/scripts/combeinrefs.py was checked in to help make sense of the new
output; this is used to get a handle on the objects still alive despite all
of shutdown's efforts to clean things up.  Staring at this output is what
motivated adding the new gc collections mentioned above.

A trick we're missing in cyclic gc:  if the uncollectable trash cycles are
partitioned into strongly connected components, then if a given SCC contains
only one object with a __del__ method, it's safe to call that __del__.  More
on that can be found here:

    http://mail.python.org/pipermail/python-dev/2003-April/034610.html

Subtle endcases abound.  If you get into that, note that Tarjan's
linear-time algorithm for finding SCCs automatically identifies SCCs in a
(reverse) topsort ordering (although that doesn't seem to be widely known
outside academia; why it's relevant will be clear(er <wink>) after reading
the above).






More information about the Python-list mailing list