[New-bugs-announce] [issue25707] Add the close method for ElementTree.iterparse() object

Serhiy Storchaka report at bugs.python.org
Mon Nov 23 08:57:25 EST 2015

New submission from Serhiy Storchaka:

If ElementTree.iterparse() is called with file names, it opens a file. When resulting iterator is not exhausted, the file lefts not closed.

>>> import xml.etree.ElementTree as ET
>>> import gc
>>> ET.iterparse('/dev/null')
<xml.etree.ElementTree._IterParseIterator object at 0xb6f9e38c>
>>> gc.collect()
__main__:1: ResourceWarning: unclosed file <_io.BufferedReader name='/dev/null'>

Martin Panter proposed in issue25688 to add an explicit way to clean it up, like a generator.close() method.

assignee: serhiy.storchaka
components: Library (Lib)
messages: 255159
nosy: serhiy.storchaka
priority: normal
severity: normal
stage: needs patch
status: open
title: Add the close method for ElementTree.iterparse() object
type: resource usage
versions: Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list