Exemple #1
0
 def foo():
     values = []
     for f in tasks.as_completed([a, b], timeout=0.12, loop=loop):
         try:
             v = yield from f
             values.append((1, v))
         except futures.TimeoutError as exc:
             values.append((2, exc))
     return values
Exemple #2
0
 def test_as_completed_concurrent(self):
     a = tasks.sleep(0.05, 'a', loop=self.loop)
     b = tasks.sleep(0.05, 'b', loop=self.loop)
     fs = {a, b}
     futs = list(tasks.as_completed(fs, loop=self.loop))
     self.assertEqual(len(futs), 2)
     waiter = tasks.wait(futs, loop=self.loop)
     done, pending = self.loop.run_until_complete(waiter)
     self.assertEqual(set(f.result() for f in done), {'a', 'b'})
Exemple #3
0
 def foo():
     values = []
     for f in tasks.as_completed([a, b], timeout=0.12, loop=self.loop):
         try:
             v = yield from f
             values.append((1, v))
         except futures.TimeoutError as exc:
             values.append((2, exc))
     return values
Exemple #4
0
 def test_as_completed_concurrent(self):
     a = tasks.sleep(0.05, 'a')
     b = tasks.sleep(0.05, 'b')
     fs = {a, b}
     futs = list(tasks.as_completed(fs))
     self.assertEqual(len(futs), 2)
     waiter = tasks.wait(futs)
     done, pending = self.loop.run_until_complete(waiter)
     self.assertEqual(set(f.result() for f in done), {'a', 'b'})
Exemple #5
0
 def test_as_completed_reverse_wait(self):
     a = tasks.sleep(0.05, 'a', loop=self.loop)
     b = tasks.sleep(0.10, 'b', loop=self.loop)
     fs = {a, b}
     futs = list(tasks.as_completed(fs, loop=self.loop))
     self.assertEqual(len(futs), 2)
     x = self.loop.run_until_complete(futs[1])
     self.assertEqual(x, 'a')
     y = self.loop.run_until_complete(futs[0])
     self.assertEqual(y, 'b')
Exemple #6
0
 def test_as_completed_reverse_wait(self):
     a = tasks.sleep(0.05, 'a')
     b = tasks.sleep(0.10, 'b')
     fs = {a, b}
     futs = list(tasks.as_completed(fs))
     self.assertEqual(len(futs), 2)
     x = self.loop.run_until_complete(futs[1])
     self.assertEqual(x, 'a')
     y = self.loop.run_until_complete(futs[0])
     self.assertEqual(y, 'b')
Exemple #7
0
    def test_as_completed_concurrent(self):
        def gen():
            when = yield
            self.assertAlmostEqual(0.05, when)
            when = yield 0
            self.assertAlmostEqual(0.05, when)
            yield 0.05

        loop = test_utils.TestLoop(gen)
        self.addCleanup(loop.close)

        a = tasks.sleep(0.05, 'a', loop=loop)
        b = tasks.sleep(0.05, 'b', loop=loop)
        fs = {a, b}
        futs = list(tasks.as_completed(fs, loop=loop))
        self.assertEqual(len(futs), 2)
        waiter = tasks.wait(futs, loop=loop)
        done, pending = loop.run_until_complete(waiter)
        self.assertEqual(set(f.result() for f in done), {'a', 'b'})
Exemple #8
0
    def test_as_completed_concurrent(self):

        def gen():
            when = yield
            self.assertAlmostEqual(0.05, when)
            when = yield 0
            self.assertAlmostEqual(0.05, when)
            yield 0.05

        loop = test_utils.TestLoop(gen)
        self.addCleanup(loop.close)

        a = tasks.sleep(0.05, 'a', loop=loop)
        b = tasks.sleep(0.05, 'b', loop=loop)
        fs = {a, b}
        futs = list(tasks.as_completed(fs, loop=loop))
        self.assertEqual(len(futs), 2)
        waiter = tasks.wait(futs, loop=loop)
        done, pending = loop.run_until_complete(waiter)
        self.assertEqual(set(f.result() for f in done), {'a', 'b'})
Exemple #9
0
    def test_as_completed_reverse_wait(self):
        def gen():
            yield 0
            yield 0.05
            yield 0

        loop = test_utils.TestLoop(gen)
        self.addCleanup(loop.close)

        a = tasks.sleep(0.05, 'a', loop=loop)
        b = tasks.sleep(0.10, 'b', loop=loop)
        fs = {a, b}
        futs = list(tasks.as_completed(fs, loop=loop))
        self.assertEqual(len(futs), 2)

        x = loop.run_until_complete(futs[1])
        self.assertEqual(x, 'a')
        self.assertAlmostEqual(0.05, loop.time())
        loop.advance_time(0.05)
        y = loop.run_until_complete(futs[0])
        self.assertEqual(y, 'b')
        self.assertAlmostEqual(0.10, loop.time())
Exemple #10
0
    def test_as_completed_reverse_wait(self):

        def gen():
            yield 0
            yield 0.05
            yield 0

        loop = test_utils.TestLoop(gen)
        self.addCleanup(loop.close)

        a = tasks.sleep(0.05, 'a', loop=loop)
        b = tasks.sleep(0.10, 'b', loop=loop)
        fs = {a, b}
        futs = list(tasks.as_completed(fs, loop=loop))
        self.assertEqual(len(futs), 2)

        x = loop.run_until_complete(futs[1])
        self.assertEqual(x, 'a')
        self.assertAlmostEqual(0.05, loop.time())
        loop.advance_time(0.05)
        y = loop.run_until_complete(futs[0])
        self.assertEqual(y, 'b')
        self.assertAlmostEqual(0.10, loop.time())
Exemple #11
0
 def foo():
     values = []
     for f in tasks.as_completed([b, c, a], loop=loop):
         values.append((yield from f))
     return values
Exemple #12
0
 def foo():
     values = []
     for f in tasks.as_completed([b, c, a], loop=self.loop):
         values.append((yield from f))
     return values