[Python-Dev] is this the fault of import_fresh_module or pickle? (original) (raw)
Eli Bendersky eliben at gmail.com
Tue Jan 8 16:19:56 CET 2013
- Previous message: [Python-Dev] Point of building without threads?
- Next message: [Python-Dev] is this the fault of import_fresh_module or pickle?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello, I'm still having some struggles with the interaction between pickle and import overriding with import_fresh_module.
_elementtree.TreeBuilder can't be pickled at this point. When I do this:
from test.support import import_fresh_module import pickle P = import_fresh_module('xml.etree.ElementTree', blocked=['_elementtree']) tb = P.TreeBuilder() print(pickle.dumps(tb))
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']) tb = P.TreeBuilder() print(pickle.dumps(tb))
I get an error from pickle.dumps:
Traceback (most recent call last): File "mix_c_py_etree.py", line 10, in print(pickle.dumps(tb)) _pickle.PicklingError: Can't pickle <class 'xml.etree.ElementTree.TreeBuilder'>: it's not the same object as xml.etree.ElementTree.TreeBuilder
Note that I didn't change the executed code sequence. All I did was import the C version of ET before the Python version. I was under the impression this had to keep working since P = import_fresh_module uses blocked=['_elementtree'] properly.
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?
Thanks in advance, Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130108/567a8958/attachment.html>
- Previous message: [Python-Dev] Point of building without threads?
- Next message: [Python-Dev] is this the fault of import_fresh_module or pickle?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]