diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-19 13:24:27 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-19 13:24:27 (GMT) |
commit | 4f418d36714787fa85652806c93405e4874bca61 (patch) | |
tree | f4240a7d9a132352f1106f0c0f14fd0729e6f96b /Lib/tempfile.py | |
parent | 41ce610d4ca12ce96aa3a9b9139e416039b18f7b (diff) | |
parent | 56cefa69ee919559cf3ca2388d12371c24402df3 (diff) | |
download | cpython-4f418d36714787fa85652806c93405e4874bca61.zip cpython-4f418d36714787fa85652806c93405e4874bca61.tar.gz cpython-4f418d36714787fa85652806c93405e4874bca61.tar.bz2 |
Issue #23700: Iterator of NamedTemporaryFile now keeps a reference to
NamedTemporaryFile instance. Patch by Bohuslav Kabrda.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r-- | Lib/tempfile.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 0522c79..0bfcbf1 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -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, |