gh-101438: Avoid reference cycle in ElementTree.iterparse. by colesbury · Pull Request #114269 · python/cpython
Refactor IterParseIterator to avoid a reference cycle between the iterator() function and the IterParseIterator() instance. This leads to more prompt clean-up of the "source" file if the returned iterator is not exhausted and not otherwise part of a reference cycle. This also avoids a test failure in the GC implementation for the free-threaded build: if the "source" file is finalized before the "iterator()" generator, a ResourceWarning is issued leading to a failure in test_iterparse(). In theory, this warning can occur in the default build as well, but is much less likely because it would require an unlucky scheduling of the GC between creation of the generator and the file object in order to change the order of finalization.
This avoids the `__next__` wrapper and the `root` property, both of which had a performance impact on the iterparse benchmark in bm_xml_etree.
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request
…honGH-114269) The iterator returned by ElementTree.iterparse() may hold on to a file descriptor. The reference cycle prevented prompt clean-up of the file descriptor if the returned iterator was not exhausted. (cherry picked from commit ce01ab5) Co-authored-by: Sam Gross <colesbury@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request
…honGH-114269) The iterator returned by ElementTree.iterparse() may hold on to a file descriptor. The reference cycle prevented prompt clean-up of the file descriptor if the returned iterator was not exhausted. (cherry picked from commit ce01ab5) Co-authored-by: Sam Gross <colesbury@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request
…-114269) (GH-114499) The iterator returned by ElementTree.iterparse() may hold on to a file descriptor. The reference cycle prevented prompt clean-up of the file descriptor if the returned iterator was not exhausted. (cherry picked from commit ce01ab5) Co-authored-by: Sam Gross <colesbury@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request
…-114269) (GH-114500) The iterator returned by ElementTree.iterparse() may hold on to a file descriptor. The reference cycle prevented prompt clean-up of the file descriptor if the returned iterator was not exhausted. (cherry picked from commit ce01ab5) Co-authored-by: Sam Gross <colesbury@gmail.com>
colesbury added a commit to colesbury/cpython that referenced this pull request
Prior to pythongh-114269, the iterator returned by ElementTree.iterparse was initialized with the root attribute as None. This restores the previous behavior.
serhiy-storchaka pushed a commit that referenced this pull request
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request
…ute (pythonGH-114755) Prior to pythongh-114269, the iterator returned by ElementTree.iterparse was initialized with the root attribute as None. This restores the previous behavior. (cherry picked from commit 66f95ea) Co-authored-by: Sam Gross <colesbury@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request
…ute (pythonGH-114755) Prior to pythongh-114269, the iterator returned by ElementTree.iterparse was initialized with the root attribute as None. This restores the previous behavior. (cherry picked from commit 66f95ea) Co-authored-by: Sam Gross <colesbury@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request
serhiy-storchaka pushed a commit that referenced this pull request
aisk pushed a commit to aisk/cpython that referenced this pull request
…honGH-114269) The iterator returned by ElementTree.iterparse() may hold on to a file descriptor. The reference cycle prevented prompt clean-up of the file descriptor if the returned iterator was not exhausted.
aisk pushed a commit to aisk/cpython that referenced this pull request
…ute (pythonGH-114755) Prior to pythongh-114269, the iterator returned by ElementTree.iterparse was initialized with the root attribute as None. This restores the previous behavior.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request
…honGH-114269) The iterator returned by ElementTree.iterparse() may hold on to a file descriptor. The reference cycle prevented prompt clean-up of the file descriptor if the returned iterator was not exhausted.