[issue25707] Add the close method for ElementTree.iterparse() object

Serhiy Storchaka report at bugs.python.org
Thu May 2 04:01:27 EDT 2019


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Implicit closing an exhausted iterator helps only the iterator is iterated to the end. If the iteration has been stopped before the end, we get a leak of the file descriptor. Closing the file descriptor in the finalizer can be deferred to undefined term, especially in implementations without reference counting. Since file descriptors are limited resource, this can cause troubles in real programs.

Reasons for close() in iterparse objects are the same as for close in files and generators.

Maybe we will need to implement the full generator protocol (send() and throw()) in the iterparse objects, but currently I do not know use cases for this.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue25707>
_______________________________________


More information about the Python-bugs-list mailing list