Repository navigation
Closed
Labels
extension-modulesC modules in the Modules dirrelease-blockerstdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or error
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2013-01-12.13:21:35.399>
created_at = <Date 2012-09-28.08:54:59.477>
labels = ['extension-modules', 'expert-XML', 'type-bug', 'library', 'release-blocker']
title = 'xml.etree.ElementTree.Element is no longer pickleable'
updated_at = <Date 2013-01-12.13:43:31.998>
user = 'https://bugs.python.org/einarfd'bugs.python.org fields:
activity = <Date 2013-01-12.13:43:31.998>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2013-01-12.13:21:35.399>
closer = 'python-dev'
components = ['Extension Modules', 'Library (Lib)', 'XML']
creation = <Date 2012-09-28.08:54:59.477>
creator = 'einarfd'
dependencies = []
files = ['28199', '28252', '28261', '28363', '28484', '28502', '28627', '28639', '28691']
hgrepos = []
issue_num = 16076
keywords = ['patch', '3.3regression']
message_count = 50.0
messages = ['171418', '171737', '172297', '172613', '172665', '176854', '177134', '177136', '177141', '177170', '177590', '177766', '178498', '178499', '178500', '178509', '178546', '178578', '178579', '178627', '178632', '178721', '178736', '178745', '178770', '178776', '178783', '178788', '178946', '179002', '179011', '179032', '179243', '179244', '179314', '179315', '179354', '179356', '179386', '179393', '179395', '179400', '179544', '179546', '179553', '179642', '179651', '179667', '179790', '179792']
nosy_count = 12.0
nosy_names = ['georg.brandl', 'jcea', 'larry', 'ezio.melotti', 'Arfrever', 'eli.bendersky', 'skrah', 'flox', 'santoso.wijaya', 'python-dev', 'einarfd', 'danielsh']
pr_nums = []
priority = 'release blocker'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue16076'
versions = ['Python 3.3', 'Python 3.4']Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirrelease-blockerstdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or error
Activity
einarfd commentedon Sep 28, 2012
The xml.etree.ElementTree.Element class is no longer pickleable in Python 3.3.0rc3 .
This is a regression from Python 3.2 where the Element class was pickleable, while the xml.etree.cElementTree.Element was not. So this is probably related to switching the ElementTree implementation in Python 3.3.
I've looked at the "what's new" documentation in Python 3.3, and there was nothing that indicated that the ElemenTree switchover would give this kind of issues.
I've run into this issues because I use the multiprocessing module to pass parsed XML documents between processes, and when I can't pickle Element objects. This stops working.
You can reproduce the issue with the following code:
import pickle
from xml.etree.ElementTree import Element
serhiy-storchaka commentedon Oct 1, 2012
In 3.2 repr(xml.etree.ElementTree.Element) is "<class 'xml.etree.ElementTree.Element'>".
In 3.3 repr(xml.etree.ElementTree.Element) is "<class 'Element'>".
elibendersky commentedon Oct 7, 2012
Will look into it, thanks for the report.
santosowijaya commentedon Oct 11, 2012
This is because, in Python 3.3, xml.etree.ElementTree.Element is overridden by the C accelerator version, _elementtree.Element.
If you remove the statement,
1708 from _elementtree import *
the behavior from Python 3.2 comes back.
santosowijaya commentedon Oct 11, 2012
OTOH, xml.etree.cElementTree.Element in Python 3.2 and earlier has never been pickleable, either.
danielsh commentedon Dec 3, 2012
Attached patch for your consideration.
I've tested pickling/unpickling and comparing the resulting object attribute by attribute (.tag, .attrib, .text, .tail for equality; and recursively .getchildren()), and 'make test' --- all seems to work.
If the approach is sound, I can submit a revised patch that also updates documentation, regression tests, and potententially updates other type objects in the same manner as this patch updates _elementtree.Element .
danielsh commentedon Dec 7, 2012
TreeBuilder was also pickleable in 3.2 but now isn't so; updating summary accordingly.
Attaching a checkpoint patch. It addresses both Element and TreeBuilder, and adds tests. The added tests fail if test___all__ is included in the test run, so the patch should not be applied as-is.
Thanks to Ezio Melotti for preliminary review and suggestions on IRC.
[-]xml.etree.ElementTree.Element is no longer pickleable[/-][+]xml.etree.ElementTree.Element and xml.etree.ElementTree.TreeBuilder are no longer pickleable[/+]danielsh commentedon Dec 7, 2012
Reattaching without the unrelated Python-ast.c change.
33 remaining items
danielsh commentedon Jan 8, 2013
Dissociating TreeBuilder from this issue per recent comments.
[-]xml.etree.ElementTree.Element and xml.etree.ElementTree.TreeBuilder are no longer pickleable[/-][+]xml.etree.ElementTree.Element is no longer pickleable[/+]danielsh commentedon Jan 8, 2013
v8 removes TreeBuilder handling (code + tests) and removes memcpy per review. (Outstanding issues in the review can be fixed post-v8, if needed.)
python-dev commentedon Jan 10, 2013
New changeset 8d6dadfecf22 by Eli Bendersky in branch '3.3':
Issue bpo-16076: make _elementtree.Element pickle-able in a way that is compatible
http://hg.python.org/cpython/rev/8d6dadfecf22
New changeset 4c268b7c86e6 by Eli Bendersky in branch 'default':
Issue bpo-16076: make _elementtree.Element pickle-able in a way that is compatible
http://hg.python.org/cpython/rev/4c268b7c86e6
elibendersky commentedon Jan 10, 2013
Fixed in 3.3 and default. Thanks for the good work, Daniel. A separate issue can be opened for TreeBuilder.
python-dev commentedon Jan 10, 2013
New changeset c46054b49b6c by Eli Bendersky in branch '3.3':
Update Misc/NEWS for issue bpo-16076
http://hg.python.org/cpython/rev/c46054b49b6c
ezio-melotti commentedon Jan 11, 2013
The fix introduced some refleaks:
$ ./python -m test -R3:2 test_xml_etree_c
test_xml_etree_c leaked [56, 56] references, sum=112
I'm still looking for the other.
ezio-melotti commentedon Jan 11, 2013
This is what I found out.
I used an easily copy/pastable one-liner that creates 3 variables: e (no children), e2 (3 children), e3 (5 children).
The leaked refs seems to be 1 for the children list + 1 for each children.
The diff I pasted in the previous *seems* to fix this (i.e. leaks in __gestate__ are gone, tests pass), but I had it crash once (couldn't reproduce after that, so it might be unrelated*), and I'm not sure it's correct.
I'm not working on this anymore now, so someone more familiar with the code can take a look, see if my patch is correct, and fix the remaining leaks.
make -j2doesn't always work right away, and sometimes I get different results if I do it again without touching the code.danielsh commentedon Jan 11, 2013
Thank for narrowing it down so much. Attached patch incorporates your
getstate fix and a fix for setstate. It passes the -R 3:2 tests.
python-dev commentedon Jan 12, 2013
New changeset 5b36768b9a11 by Eli Bendersky in branch '3.3':
Issue bpo-16076: fix refleak in pickling of Element.
http://hg.python.org/cpython/rev/5b36768b9a11
New changeset 848738d3c40f by Eli Bendersky in branch 'default':
Close bpo-16076: fix refleak in pickling of Element.
http://hg.python.org/cpython/rev/848738d3c40f
python-dev commentedon Jan 12, 2013
New changeset 4501813ea676 by Eli Bendersky in branch '3.3':
Issue bpo-16076: check for return value of PyTuple_New for args (following
http://hg.python.org/cpython/rev/4501813ea676
New changeset 7313096e0bad by Eli Bendersky in branch 'default':
Issue bpo-16076: check for return value of PyTuple_New for args (following
http://hg.python.org/cpython/rev/7313096e0bad