]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
parallel: obey iterator protocol
authorJosh Durgin <josh.durgin@dreamhost.com>
Wed, 25 Apr 2012 00:47:51 +0000 (17:47 -0700)
committerJosh Durgin <josh.durgin@dreamhost.com>
Wed, 25 Apr 2012 00:48:05 +0000 (17:48 -0700)
Once it raises StopIteration, it must continue to do so on subsequent calls to next().

teuthology/parallel.py

index c3463a04080756a5e336abb8a4799dada42b4756..a3693ea6041cbcdbd38c2a271cd33ceea9beec01 100644 (file)
@@ -36,6 +36,7 @@ class parallel(object):
         self.results = gevent.queue.Queue()
         self.count = 0
         self.any_spawned = False
+        self.iteration_stopped = False
 
     def spawn(self, func, *args, **kwargs):
         self.count += 1
@@ -65,10 +66,12 @@ class parallel(object):
         return self
 
     def next(self):
-        if not self.any_spawned:
+        if not self.any_spawned or self.iteration_stopped:
             raise StopIteration()
         result = self.results.get()
         if isinstance(result, BaseException):
+            if isinstance(result, StopIteration):
+                self.iteration_stopped = True
             raise result
         return result