def imap_memory_check(self, concurrency): # checks that imap is strictly # ordered and consumes a constant amount of memory p = GreenPool(concurrency) count = 1000 it = p.imap(passthru, xrange(count)) latest = -1 while True: try: i = it.next() except StopIteration: break if latest == -1: gc.collect() initial_obj_count = len(gc.get_objects()) self.assert_(i > latest) latest = i if latest % 5 == 0: sleep(0.001) if latest % 10 == 0: gc.collect() objs_created = len(gc.get_objects()) - initial_obj_count self.assert_(objs_created < 25 * concurrency, objs_created) # make sure we got to the end self.assertEquals(latest, count - 1)
def imap_memory_check (self, concurrency): # checks that imap is strictly # ordered and consumes a constant amount of memory p = GreenPool(concurrency) count = 1000 it = p.imap(passthru, xrange(count)) latest = -1 while True: try: i = it.next() except StopIteration: break if latest == -1: gc.collect() initial_obj_count = len(gc.get_objects()) self.assert_(i > latest) latest = i if latest % 5 == 0: sleep(0.001) if latest % 10 == 0: gc.collect() objs_created = len(gc.get_objects()) - initial_obj_count self.assert_(objs_created < 25 * concurrency, objs_created) # make sure we got to the end self.assertEquals(latest, count - 1)
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 = GreenPool(4) def raiser(item): if item == 1 or item == 7: raise RuntimeError("intentional error") else: return item it = p.imap(raiser, xrange(10)) results = [] while True: try: results.append(it.next()) except RuntimeError: results.append('r') except StopIteration: break self.assertEquals(results, [0, 'r', 2, 3, 4, 5, 6, 'r', 8, 9])
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 = GreenPool(4) def raiser(item): if item == 1 or item == 7: raise RuntimeError("intentional error") else: return item it = p.imap(raiser, xrange(10)) results = [] while True: try: results.append(it.next()) except RuntimeError: results.append("r") except StopIteration: break self.assertEquals(results, [0, "r", 2, 3, 4, 5, 6, "r", 8, 9])
def test_imap_multi_args(self): p = GreenPool(4) result_list = list(p.imap(passthru2, xrange(10), xrange(10, 20))) self.assertEquals(result_list, list(itertools.izip(xrange(10), xrange(10, 20))))
def test_imap_nonefunc(self): p = GreenPool(4) result_list = list(p.imap(None, xrange(10))) self.assertEquals(result_list, [(x, ) for x in xrange(10)])
def test_empty_imap(self): p = GreenPool(4) result_iter = p.imap(passthru, []) self.assertRaises(StopIteration, result_iter.next)
def test_imap(self): p = GreenPool(4) result_list = list(p.imap(passthru, xrange(10))) self.assertEquals(result_list, list(xrange(10)))
def test_imap_multi_args(self): p = GreenPool(4) result_list = list(p.imap(passthru2, xrange(10), xrange(10, 20))) self.assertEquals(result_list, list(itertools.izip(xrange(10), xrange(10, 20))))
def test_imap_nonefunc(self): p = GreenPool(4) result_list = list(p.imap(None, xrange(10))) self.assertEquals(result_list, [(x,) for x in xrange(10)])
def test_empty_imap(self): p = GreenPool(4) result_iter = p.imap(passthru, []) self.assertRaises(StopIteration, result_iter.next)
def test_imap(self): p = GreenPool(4) result_list = list(p.imap(passthru, xrange(10))) self.assertEquals(result_list, list(xrange(10)))