[Python-Dev] Better module shutdown procedure

Amaury Forgeot d'Arc amauryfa at gmail.com
Fri Oct 16 10:01:07 CEST 2009

2009/10/16 Neil Schemenauer <nas at arctrix.com>:
> After some experimentation I realize this idea is not ready yet.
> The main problem comes from references to Python objects that
> modules keep but don't expose to the garbage collector. For example,
> gcmodule.c has a static pointer "tmod" that is a reference to the
> "time" module. This reference prevents the "time" module from being
> freed during interpreter shutdown.
> Ideally, I suppose modules should be treated like any other object
> and have tp_traverse and tp_clear methods that deal with these sorts
> of pointers. They would have to delegated to the instance since each
> module would have its own implementation.

Note since python 3.0 (and PEP 3121), the PyModuleDef structure has
some members like m_traverse, m_clear and m_free for this very
So far, nobody cared to implement these methods for any module. Maybe
one should start at least for static PyObject* that contain references
to modules.

Amaury Forgeot d'Arc

More information about the Python-Dev mailing list