From 2511e14c4f147cbdf08fd4d7c6c3f187812ec27a Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 12 Jan 2009 16:17:12 +0600 Subject: [PATCH] proc module: renames wait to waitall; it only supports list of Procs now but not individual Procs like it did before --- eventlet/proc.py | 17 ++++------------- greentest/test__proc.py | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/eventlet/proc.py b/eventlet/proc.py index f259cff..52f5420 100644 --- a/eventlet/proc.py +++ b/eventlet/proc.py @@ -159,22 +159,13 @@ class LinkToGreenlet(Link): def _fire_exception(self, source, throw_args): self.listener.throw(getLinkedFailed(source, *throw_args)) -def wait(linkable_or_list, trap_errors=False): - if hasattr(linkable_or_list, 'link'): - event = coros.event() - linkable_or_list.link(event) - try: - return event.wait() - except Exception: - if trap_errors: - return - raise +def waitall(lst, trap_errors=False): queue = coros.queue() - results = [None] * len(linkable_or_list) - for (index, linkable) in enumerate(linkable_or_list): + results = [None] * len(lst) + for (index, linkable) in enumerate(lst): linkable.link(decorate_send(queue, index)) count = 0 - while count < len(linkable_or_list): + while count < len(lst): try: index, value = queue.wait() except Exception: diff --git a/greentest/test__proc.py b/greentest/test__proc.py index 2c34398..f6ed1be 100644 --- a/greentest/test__proc.py +++ b/greentest/test__proc.py @@ -166,7 +166,7 @@ class TestCase(LimitedTestCase): raise AssertionError('should not get there') with timeout(DELAY, None): - print repr(proc.wait(myproc)) + print repr(proc.waitall([myproc])) raise AssertionError('should not get there') assert proc_finished_flag == [], proc_finished_flag @@ -201,7 +201,7 @@ class TestReturn_link(TestCase): self.assertEqual(event.wait(), result) self.assertEqual(queue.wait(), result) self.assertRaises(kill_exc_type, receiver.wait) - self.assertRaises(kill_exc_type, proc.wait, receiver) + self.assertRaises(kill_exc_type, proc.waitall, [receiver]) sleep(DELAY) assert not proc_flag, proc_flag @@ -233,7 +233,7 @@ class TestRaise_link(TestCase): with timeout(DELAY): self.assertRaises(ValueError, event.wait) self.assertRaises(ValueError, queue.wait) - self.assertRaises(kill_exc_type, proc.wait, receiver) + self.assertRaises(kill_exc_type, proc.waitall, [receiver]) sleep(DELAY) assert not proc_flag, proc_flag assert not callback_flag, callback_flag @@ -264,7 +264,7 @@ class TestRaise_link(TestCase): with timeout(DELAY): self.assertRaises(proc.ProcExit, event.wait) self.assertRaises(proc.ProcExit, queue.wait) - self.assertRaises(kill_exc_type, proc.wait, receiver) + self.assertRaises(kill_exc_type, proc.waitall, [receiver]) sleep(DELAY) assert not proc_flag, proc_flag @@ -289,7 +289,7 @@ class TestStuff(unittest.TestCase): x = proc.spawn(lambda : 1) y = proc.spawn(lambda : 2) z = proc.spawn(lambda : 3) - self.assertEqual(proc.wait([x, y, z]), [1, 2, 3]) + self.assertEqual(proc.waitall([x, y, z]), [1, 2, 3]) e = coros.event() x.link(e) self.assertEqual(e.wait(), 1) @@ -297,7 +297,7 @@ class TestStuff(unittest.TestCase): e = coros.event() x.link(e) self.assertEqual(e.wait(), 1) - self.assertEqual([proc.wait(X) for X in [x, y, z]], [1, 2, 3]) + self.assertEqual([proc.waitall([X]) for X in [x, y, z]], [[1], [2], [3]]) def test_wait_error(self): def x(): @@ -310,10 +310,10 @@ class TestStuff(unittest.TestCase): x.link(y) y.link(z) z.link(y) - self.assertRaises(ValueError, proc.wait, [x, y, z]) - self.assertRaises(proc.LinkedFailed, proc.wait, x) - self.assertEqual(proc.wait(z), 3) - self.assertRaises(ValueError, proc.wait, y) + self.assertRaises(ValueError, proc.waitall, [x, y, z]) + self.assertRaises(proc.LinkedFailed, proc.waitall, [x]) + self.assertEqual(proc.waitall([z]), [3]) + self.assertRaises(ValueError, proc.waitall, [y]) def test_wait_all_exception_order(self): # if there're several exceptions raised, the earliest one must be raised by wait @@ -323,7 +323,7 @@ class TestStuff(unittest.TestCase): a = proc.spawn(badint) b = proc.spawn(int, 'second') try: - proc.wait([a, b]) + proc.waitall([a, b]) except ValueError, ex: assert 'second' in str(ex), repr(str(ex))