From: Josh Durgin Date: Wed, 25 Apr 2012 00:47:51 +0000 (-0700) Subject: parallel: obey iterator protocol X-Git-Tag: 1.1.0~2565 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b32b693ab201068f785f64877d02a3eabe01d2e8;p=teuthology.git parallel: obey iterator protocol Once it raises StopIteration, it must continue to do so on subsequent calls to next(). --- diff --git a/teuthology/parallel.py b/teuthology/parallel.py index c3463a040..a3693ea60 100644 --- a/teuthology/parallel.py +++ b/teuthology/parallel.py @@ -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