◐ Shell
clean mode source ↗

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.

@colesbury

serhiy-storchaka

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

serhiy-storchaka

@serhiy-storchaka

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Jan 23, 2024
…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

Jan 23, 2024
…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

Jan 23, 2024
…-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

Jan 23, 2024
…-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>

Prometheus3375

colesbury added a commit to colesbury/cpython that referenced this pull request

Jan 30, 2024
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

Jan 31, 2024
…H-114755)

Prior to gh-114269, the iterator returned by ElementTree.iterparse was
initialized with the root attribute as None. This restores the previous
behavior.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Jan 31, 2024
…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

Jan 31, 2024
…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

Jan 31, 2024
…bute (GH-114755) (GH-114798)

Prior to gh-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

Jan 31, 2024
…bute (GH-114755) (GH-114799)

Prior to gh-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>

aisk pushed a commit to aisk/cpython that referenced this pull request

Feb 11, 2024
…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

Feb 11, 2024
…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

Sep 2, 2024
…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.