proc module: renames wait to waitall; it only supports list of Procs now but not individual Procs like it did before
This commit is contained in:
@@ -159,22 +159,13 @@ class LinkToGreenlet(Link):
|
|||||||
def _fire_exception(self, source, throw_args):
|
def _fire_exception(self, source, throw_args):
|
||||||
self.listener.throw(getLinkedFailed(source, *throw_args))
|
self.listener.throw(getLinkedFailed(source, *throw_args))
|
||||||
|
|
||||||
def wait(linkable_or_list, trap_errors=False):
|
def waitall(lst, 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
|
|
||||||
queue = coros.queue()
|
queue = coros.queue()
|
||||||
results = [None] * len(linkable_or_list)
|
results = [None] * len(lst)
|
||||||
for (index, linkable) in enumerate(linkable_or_list):
|
for (index, linkable) in enumerate(lst):
|
||||||
linkable.link(decorate_send(queue, index))
|
linkable.link(decorate_send(queue, index))
|
||||||
count = 0
|
count = 0
|
||||||
while count < len(linkable_or_list):
|
while count < len(lst):
|
||||||
try:
|
try:
|
||||||
index, value = queue.wait()
|
index, value = queue.wait()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@@ -166,7 +166,7 @@ class TestCase(LimitedTestCase):
|
|||||||
raise AssertionError('should not get there')
|
raise AssertionError('should not get there')
|
||||||
|
|
||||||
with timeout(DELAY, None):
|
with timeout(DELAY, None):
|
||||||
print repr(proc.wait(myproc))
|
print repr(proc.waitall([myproc]))
|
||||||
raise AssertionError('should not get there')
|
raise AssertionError('should not get there')
|
||||||
assert proc_finished_flag == [], proc_finished_flag
|
assert proc_finished_flag == [], proc_finished_flag
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ class TestReturn_link(TestCase):
|
|||||||
self.assertEqual(event.wait(), result)
|
self.assertEqual(event.wait(), result)
|
||||||
self.assertEqual(queue.wait(), result)
|
self.assertEqual(queue.wait(), result)
|
||||||
self.assertRaises(kill_exc_type, receiver.wait)
|
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)
|
sleep(DELAY)
|
||||||
assert not proc_flag, proc_flag
|
assert not proc_flag, proc_flag
|
||||||
@@ -233,7 +233,7 @@ class TestRaise_link(TestCase):
|
|||||||
with timeout(DELAY):
|
with timeout(DELAY):
|
||||||
self.assertRaises(ValueError, event.wait)
|
self.assertRaises(ValueError, event.wait)
|
||||||
self.assertRaises(ValueError, queue.wait)
|
self.assertRaises(ValueError, queue.wait)
|
||||||
self.assertRaises(kill_exc_type, proc.wait, receiver)
|
self.assertRaises(kill_exc_type, proc.waitall, [receiver])
|
||||||
sleep(DELAY)
|
sleep(DELAY)
|
||||||
assert not proc_flag, proc_flag
|
assert not proc_flag, proc_flag
|
||||||
assert not callback_flag, callback_flag
|
assert not callback_flag, callback_flag
|
||||||
@@ -264,7 +264,7 @@ class TestRaise_link(TestCase):
|
|||||||
with timeout(DELAY):
|
with timeout(DELAY):
|
||||||
self.assertRaises(proc.ProcExit, event.wait)
|
self.assertRaises(proc.ProcExit, event.wait)
|
||||||
self.assertRaises(proc.ProcExit, queue.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)
|
sleep(DELAY)
|
||||||
assert not proc_flag, proc_flag
|
assert not proc_flag, proc_flag
|
||||||
@@ -289,7 +289,7 @@ class TestStuff(unittest.TestCase):
|
|||||||
x = proc.spawn(lambda : 1)
|
x = proc.spawn(lambda : 1)
|
||||||
y = proc.spawn(lambda : 2)
|
y = proc.spawn(lambda : 2)
|
||||||
z = proc.spawn(lambda : 3)
|
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()
|
e = coros.event()
|
||||||
x.link(e)
|
x.link(e)
|
||||||
self.assertEqual(e.wait(), 1)
|
self.assertEqual(e.wait(), 1)
|
||||||
@@ -297,7 +297,7 @@ class TestStuff(unittest.TestCase):
|
|||||||
e = coros.event()
|
e = coros.event()
|
||||||
x.link(e)
|
x.link(e)
|
||||||
self.assertEqual(e.wait(), 1)
|
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 test_wait_error(self):
|
||||||
def x():
|
def x():
|
||||||
@@ -310,10 +310,10 @@ class TestStuff(unittest.TestCase):
|
|||||||
x.link(y)
|
x.link(y)
|
||||||
y.link(z)
|
y.link(z)
|
||||||
z.link(y)
|
z.link(y)
|
||||||
self.assertRaises(ValueError, proc.wait, [x, y, z])
|
self.assertRaises(ValueError, proc.waitall, [x, y, z])
|
||||||
self.assertRaises(proc.LinkedFailed, proc.wait, x)
|
self.assertRaises(proc.LinkedFailed, proc.waitall, [x])
|
||||||
self.assertEqual(proc.wait(z), 3)
|
self.assertEqual(proc.waitall([z]), [3])
|
||||||
self.assertRaises(ValueError, proc.wait, y)
|
self.assertRaises(ValueError, proc.waitall, [y])
|
||||||
|
|
||||||
def test_wait_all_exception_order(self):
|
def test_wait_all_exception_order(self):
|
||||||
# if there're several exceptions raised, the earliest one must be raised by wait
|
# 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)
|
a = proc.spawn(badint)
|
||||||
b = proc.spawn(int, 'second')
|
b = proc.spawn(int, 'second')
|
||||||
try:
|
try:
|
||||||
proc.wait([a, b])
|
proc.waitall([a, b])
|
||||||
except ValueError, ex:
|
except ValueError, ex:
|
||||||
assert 'second' in str(ex), repr(str(ex))
|
assert 'second' in str(ex), repr(str(ex))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user