[Python-Dev] is this the fault of import_fresh_module or pickle?

Eli Bendersky eliben at gmail.com
Tue Jan 8 17:36:04 CET 2013


On Tue, Jan 8, 2013 at 8:05 AM, Stefan Krah <stefan at bytereef.org> wrote:

> Eli Bendersky <eliben at gmail.com> wrote:
> > Everything works fine. However, if I add import_fresh_module for the C
> module:
> >
> > from test.support import import_fresh_module
> > import pickle
> > C = import_fresh_module('xml.etree.ElementTree', fresh=['_elementtree'])
> > P = import_fresh_module('xml.etree.ElementTree',
> blocked=['_elementtree'])
>
> sys.modules still contains the C version at this point, so:
>
> sys.modules['xml.etree.ElementTree'] = P
>
>
> > tb = P.TreeBuilder()
> > print(pickle.dumps(tb))
>
>
>
> > This interaction only seems to happen with pickle. What's going on here?
> Can we
> > somehow improve import_fresh_module to avoid this? Perhaps actually
> deleting
> > previously imported modules with some special keyword flag?
>
> pickle always looks up sys.modules['xml.etree.ElementTree']. Perhaps we
> could improve something, but this requirement is rather special; personally
> I'm okay with switching sys.modules explicitly in the tests, because that
> reminds me of what pickle does.
>

Wouldn’t it be be better if import_fresh_module or some alternative
function could do that for you? I mean, wipe out the import cache for
certain modules I don't want to be found?

Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130108/62ec33d6/attachment.html>


More information about the Python-Dev mailing list