def test_imap_raises(self):
# testing the case where the function raises an exception;
# both that the caller sees that exception, and that the iterator
# continues to be usable to get the rest of the items
p = eventlet.GreenPool(4)
def raiser(item):
if item == 1 or item == 7:
raise RuntimeError("intentional error")
else:
return item
it = p.imap(raiser, range(10))
results = []
while True:
try:
results.append(six.next(it))
except RuntimeError:
results.append('r')
except StopIteration:
break
self.assertEqual(results, [0, 'r', 2, 3, 4, 5, 6, 'r', 8, 9])
评论列表
文章目录