Issue #23700: Iterator of NamedTemporaryFile now keeps a reference to

NamedTemporaryFile instance.  Patch by Bohuslav Kabrda.
This commit is contained in:
Serhiy Storchaka 2015-03-19 15:23:15 +02:00
parent 86fdbf3152
commit 56cefa69ee
3 changed files with 19 additions and 1 deletions

View file

@ -426,7 +426,9 @@ class _TemporaryFileWrapper:
# iter() doesn't use __getattr__ to find the __iter__ method
def __iter__(self):
return iter(self.file)
# don't return iter(self.file), but yield from it to avoid closing
# file as long as it's being used as iterator, see issue #23000
yield from iter(self.file)
def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None,