Exemplo n.º 1
0
 async def main():
     evt = asyncio.Event()
     async with CoroutineExecutor():
         async with CoroutineExecutor():
             async with CoroutineExecutor() as exe3:
                 t1 = await exe3.submit(f, 0.01, evt=evt)
                 t2 = await exe3.submit(f, 0.50)
                 tasks.extend([t1, t2])
                 await evt.wait()
                 raise Exception('oh noes')
Exemplo n.º 2
0
 async def main():
     evt1 = asyncio.Event()
     evt2 = asyncio.Event()
     async with CoroutineExecutor() as exe1:
         t3 = await exe1.submit(f, 0.01, evt=evt1)
         t4 = await exe1.submit(f, 1.0)
         async with CoroutineExecutor() as exe2:
             t1 = await exe2.submit(f, 0.01, evt=evt2)
             t2 = await exe2.submit(f, 1.0)
             tasks.extend([t1, t2, t3, t4])
             await evt1.wait()
             await evt2.wait()
             raise Exception('oh noes')
Exemplo n.º 3
0
    async def main():
        async with CoroutineExecutor() as exe:
            t1 = await exe.submit(f, 0.001, results)
            t2 = await exe.submit(f, 0.002, results)

        assert t1.done()
        assert t2.done()
Exemplo n.º 4
0
    async def main():
        async with CoroutineExecutor(initializer=fn, initargs=args) as exe:
            t1 = await exe.submit(f, 0.001)
            t2 = await exe.submit(f, 0.002)

        assert t1.done()
        assert t2.done()
Exemplo n.º 5
0
    async def main():
        async with CoroutineExecutor() as exe:
            t1 = await exe.submit(f, exc_delay, results, error=True)
            t2 = await exe.submit(f, 0.2, results)

        assert t1.done() and t1.exception() and not t1.cancelled()
        assert t2.done() and not t2.exception() and t2.cancelled()
Exemplo n.º 6
0
 async def outer(evt: asyncio.Event):
     async with CoroutineExecutor() as exe:
         t1 = await exe.submit(f, 4.0)
         t2 = await exe.submit(f, 4.0)
         tasks.extend([t1, t2])
         evt.set()
         # This await will *not* be cancelled.
         await asyncio.sleep(0.1)
Exemplo n.º 7
0
    async def main():
        async with CoroutineExecutor() as executor:
            await executor.submit(f, random())
            await executor.submit(f, random())
            await executor.submit(f, random())

            await executor.submit(producer1, executor)
            await executor.submit(producer2, executor)
Exemplo n.º 8
0
    async def main():
        kwargs = dict(max_workers=w)
        with elapsed():
            async with CoroutineExecutor(**kwargs) as exe:
                tasks = [await exe.submit(job) for i in range(n)]

        assert all(t.done() for t in tasks)
        assert [t.result() for t in tasks] == [123] * n
Exemplo n.º 9
0
    async def main():
        exe = CoroutineExecutor()
        t1 = await exe.submit(f, 0.01)
        t2 = await exe.submit(f, 0.05)
        await exe.shutdown(wait=True)  # default

        assert t1.done() and not t1.cancelled()
        assert t2.done() and not t2.cancelled()
Exemplo n.º 10
0
 async def outer(evt: asyncio.Event):
     async with CoroutineExecutor(suppress_task_errors=True) as exe:
         t1 = await exe.submit(f, 0.1)
         t2 = await exe.submit(f, 0.1)
         tasks.extend([t1, t2])
         evt.set()
         # This await will *not* be cancelled.
         await asyncio.sleep(0.2)
Exemplo n.º 11
0
    async def main():
        kwargs = dict(max_workers=w, max_backlog=b)
        with elapsed():
            async with CoroutineExecutor(**kwargs) as exe:
                for i in range(n):
                    await exe.submit_queue(job)
                    # print(f'Submitted job {i}')

        assert len(results) == n
Exemplo n.º 12
0
    async def main():
        evt = asyncio.Event()

        async with CoroutineExecutor() as exe:
            await exe.submit(f, 0.01, evt=evt)
            await exe.submit(f, 0.05)

        got_to_here.append(1)
        await evt.wait()
        await exe.submit(f, 0.02)
Exemplo n.º 13
0
    async def main():
        exe = CoroutineExecutor()
        t1 = await exe.submit(f, 0.5)
        t2 = await exe.submit(f, 0.9)
        if with_interruption:
            await asyncio.sleep(sleep_time)
        await exe.shutdown(wait=False)

        assert t1.done() and (t1.cancelled() == t1cancelled)
        assert t2.done() and (t2.cancelled() == t2cancelled)
Exemplo n.º 14
0
    async def main():
        kwargs = dict(max_workers=10)
        with elapsed() as f:
            async with CoroutineExecutor(**kwargs) as exe:
                tasks = [await exe.submit(job, item) for item in items]

        assert all(t.done() for t in tasks)
        assert [t.result() for t in tasks] == items
        # Speedup is roughly 10 times
        concurrency = sum(items) / f()
        print(f(), sum(items), concurrency)
        assert concurrency > 7
Exemplo n.º 15
0
    async def main():
        kwargs = dict(max_workers=1)
        with elapsed() as f:
            async with CoroutineExecutor(**kwargs) as exe:
                tasks = [await exe.submit(job, item) for item in items]

        assert all(t.done() for t in tasks)
        assert [t.result() for t in tasks] == items
        # Elapsed time is greater than the sum of each individual
        # time.
        print(f(), sum(items))
        assert f() > sum(items)
Exemplo n.º 16
0
 async def outer(evt: asyncio.Event):
     async with CoroutineExecutor(suppress_task_errors=True) as exe:
         t1 = await exe.submit(f, 0.01, evt=evt)
         t2 = await exe.submit(f, 5.0)
         tasks.extend([t1, t2])
         await asyncio.sleep(1.0)
Exemplo n.º 17
0
 async def main():
     async with CoroutineExecutor(initializer=123) as exe:
         await exe.submit(f, 0.001)
         await exe.submit(f, 0.002)
Exemplo n.º 18
0
 async def outer(evt: asyncio.Event):
     async with CoroutineExecutor() as exe:
         t1 = await exe.submit(f, 0.01, evt=evt)
         t2 = await exe.submit(f, 5.0)
         tasks.extend([t1, t2])
Exemplo n.º 19
0
 async def main():
     async with CoroutineExecutor() as exe:
         results = exe.map(f, times)
         assert [v async for v in results] == times
Exemplo n.º 20
0
 async def main():
     async with CoroutineExecutor() as exe:
         tasks.append(await exe.submit(f, 0.01, exe))
         tasks.append(await exe.submit(f, 0.02, exe))
Exemplo n.º 21
0
 async def main():
     async with CoroutineExecutor() as exe:
         async for r in exe.map(f, times):
             results.append(r)