Esempio n. 1
0
        def test():
            p = Pool(1)
            # batch fn called 3 times since the pool only allows one
            # call at a time.
            self.assertEquals([(2, 1),
                               (3, 1),
                               (4, 1)], p.pmap(add_n, [1,2,3]))

            self.assertEquals([(2, 1),
                               (3, 1),
                               (4, 1)], sorted(p.pmap_unordered(add_n, [1,2,3])))
Esempio n. 2
0
        def test():
            p = Pool(1)
            g = p.spawn(add_n, 1)
            self.assertTrue(p.full())
            p.wait_available()
            self.assertFalse(p.full())
            self.assertTrue(g.ready())
            self.assertEquals(2, g.get())

            g = p.spawn(add_n, 1)
            self.assertTrue(p.full())
            g2 = p.spawn(add_n, 2)
            self.assertTrue(g.ready())
            self.assertEquals(2, g.get())
            self.assertEquals(3, g2.get())
Esempio n. 3
0
        def test(fn):
            NUM_BATCH_CALLS[0] = 0

            p = Pool(1)
            it = iter([1,2,3])
            result_it = getattr(p, fn)(add_n, it, n=2)
            results = []
            # We need to call next() once so the generator runs.
            results.append(next(result_it))
            for _ in xrange(200):
                # Wait for the pool to clear - even though we're not touching
                # the result generator, imap should still continue queueing
                # so long as the pool is empty.
                gevent.sleep(0)
                p.wait_available()
                if NUM_BATCH_CALLS[0] == 3:
                    break
            self.assertEquals(3, NUM_BATCH_CALLS[0])
            self.assertRaises(StopIteration, it.next)
            results.extend(result_it)
            self.assertEquals([3, 4, 5], sorted(results))