[Python-Dev] PEP 442 aftermath: module globals at shutdown
Antoine Pitrou
solipsis at pitrou.net
Tue Jul 30 23:32:23 CEST 2013
On Tue, 30 Jul 2013 12:58:58 -0700
Guido van Rossum <guido at python.org> wrote:
> I'm very excited to see this happening! It's been a constant pain and
> one of the things I've always regretted. Thanks Antoine!
Note this is currently imperfect. I've identified two reasons why a
pure Python module could stay alive even after being removed from
sys.modules:
- it is held alive by a C extension: the main example is the locale
module, which is held alive by _io and in turn keeps alive other
Python modules (such as collections or re). But there is also the
readline module, whose completer can keep alive other stuff (this
is aggravated by the fact the readline module currently doesn't
have a proper dealloc routine).
- it is held alive through builtins: the site module patches builtins
with additional objects, which themselves keep references to the site
module's globals, and with it other modules
Regards
Antoine.
>
> --Guido
>
> On Tue, Jul 30, 2013 at 11:42 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> >
> > Hello,
> >
> > PEP 442 has now been committed in time for testing in Alpha 1.
> >
> > This paves the way for the removal of another well-known annoyance: the
> > behaviour of module globals at shutdown. Now that reference cycles
> > aren't a barrier to object finalization anymore, we shouldn't need
> > to set module globals to None before trying to reclaim modules.
> > (and then, we don't need to cache global functions for use in
> > finalizers, either)
> >
> > I have a patch to suppress the hack in
> > http://bugs.python.org/issue18214
> > Once I get to add some tests, I would like to commit it soon too!
> >
> > Regards
> >
> > Antoine.
>
More information about the Python-Dev
mailing list