Module gets garbage collected; its globals become None

Martin v. Löwis martin at v.loewis.de
Sat May 24 08:11:26 EDT 2003


Steven Taschuk <staschuk at telusplanet.net> writes:

> Is the assumption that modules only ever get collected at shutdown?

It used to be the case for a long time, in particular because of the
cycles (and because modules didn't implement tp_traverse first). These
days, cyclic gc finds modules as well.

However, the expectation still is that modules live until the end,
with the exception of reloaded modules (which even carry over the
dictionary). This is the typical case, so whatever change is made,
breakage of the shutdown code is probably unacceptable.

> Scratch that idea.

Talking about bogus ideas: leaving collection of modules to cyclic gc
is bogus as well. A global object might have a finalizer and a cycle
with its module. Currently, such an object gets finalized at
shutdown. Cyclic gc alone would move it into gc.garbage instead of
finalizing it.

Regards,
Martin





More information about the Python-list mailing list