[Python-Dev] is this the fault of import_fresh_module or pickle? (original) (raw)
R. David Murray rdmurray at bitdance.com
Tue Jan 8 17:37:59 CET 2013
- Previous message: [Python-Dev] is this the fault of import_fresh_module or pickle?
- Next message: [Python-Dev] is this the fault of import_fresh_module or pickle?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 08 Jan 2013 17:05:50 +0100, Stefan Krah <stefan at bytereef.org> wrote:
Eli Bendersky <eliben at gmail.com> wrote: > Everything works fine. However, if I add importfreshmodule for the C module: > > from test.support import importfreshmodule > import pickle > C = importfreshmodule('xml.etree.ElementTree', fresh=['elementtree']) > P = importfreshmodule('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 importfreshmodule 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.
Handling this case is why having a context-manager form of import_fresh_module was suggested earlier in this meta-thread. At least, I think that would solve it, I haven't tried it :)
--David
- Previous message: [Python-Dev] is this the fault of import_fresh_module or pickle?
- Next message: [Python-Dev] is this the fault of import_fresh_module or pickle?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]