Added assertion in greenpool to prevent infinite waits. Thanks to rtyler for the horrifying idea.

This commit is contained in:
Ryan Williams
2010-03-17 17:03:16 -07:00
parent 18625a0fd6
commit 0179da8cf2
2 changed files with 8 additions and 0 deletions

View File

@@ -110,6 +110,9 @@ class GreenPool(object):
def waitall(self):
"""Waits until all greenthreads in the pool are finished working."""
assert greenthread.getcurrent() not in self.coroutines_running, \
"Calling waitall() from within one of the "\
"GreenPool's greenthreads will never terminate."
if self.running():
self.no_coros_running.wait()

View File

@@ -302,6 +302,11 @@ class GreenPool(tests.LimitedTestCase):
p = greenpool.GreenPool()
p.waitall()
def test_recursive_waitall(self):
p = greenpool.GreenPool()
gt = p.spawn(p.waitall)
self.assertRaises(AssertionError, gt.wait)
class GreenPile(tests.LimitedTestCase):
def test_pile(self):