From 43621dc1ac626f7ce3322cee8b7908a93af20f26 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Thu, 11 Jun 2015 09:21:53 +1200 Subject: Close iterables at the end of iteration This fixes a bug where if iteration is interrupted, we're stuck until the iterable is garbage collected, which can be a very long time (e.g. if the iterable is held in an exception stack frame). Co-authored-by: Stuart McLaren Change-Id: Ibe9990e8c337c117a978b1cd8ec388c4bc6d3b4b Closes-bug: 1461678 --- glanceclient/common/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'glanceclient/common/utils.py') diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index b199bf3..bba0cab 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -434,7 +434,11 @@ class IterableWithLength(object): self.length = length def __iter__(self): - return self.iterable + try: + for chunk in self.iterable: + yield chunk + finally: + self.iterable.close() def next(self): return next(self.iterable) -- cgit v1.2.1