From 2ea50a175781db413892ace970a0e6314607e240 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Thu, 18 Dec 2008 19:25:31 +0600 Subject: [PATCH] coros.JobGroup bug fix: if there was a second exception int the group it wouldb't be delivered to the job --- eventlet/coros.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/eventlet/coros.py b/eventlet/coros.py index 5a93406..e3a1cb1 100644 --- a/eventlet/coros.py +++ b/eventlet/coros.py @@ -427,13 +427,16 @@ class JobGroup(object): return job def kill_all(self, *throw_args): - assert self._waiter_job.poll('run') == 'run' + assert self._waiter_job.poll('run') == 'run', '_waiter_job must live' for job in self._jobs: g = job.greenlet if g is not None: api.get_hub().schedule_call(0, g.throw, *throw_args) api.sleep(0) + # QQQ: add kill_all_later(seconds, throw_args) + # add kill_delay attribute + def complete(self, *jobs): assert self._waiter_job.poll('run') == 'run' left = set(jobs) @@ -461,21 +464,22 @@ class JobGroup(object): return [x.wait() for x in self._jobs] def _waiter(self): + # XXX: this lives forever, fix it to exit after all jobs died + # XXX: add __nonzero__ method that returns whether JobGroup is alive + # XXX: 3 states: True (alive), finishing, False (all dead) while True: job, result, throw_args = self._queue.wait() if throw_args is None: - job.event.send(result) + if not job.event.ready(): + job.event.send(result) else: + if not job.event.ready(): + job.event.send_exception(*throw_args) if self._killerror is None: type = throw_args[0] self._killerror = JobGroupExit('Killed because of %s in the group' % type.__name__) self.kill_all(self._killerror) - job.event.send_exception(*throw_args) # cannot exit here, as I need to deliver GreenExits - else: - # another exception, ignore it - pass - class multievent(object): """is an event that can hold more than one value (it cannot be cancelled though)