コード例 #1
0
async def test_map_n():
    todo = range(2, 11)
    async with AioPool(size=3) as pool:
        futures = pool.map_n(wrk, todo, cb)

    results = [getres.flat(f) for f in futures]
    assert 2 * sum(todo) == sum(results)
コード例 #2
0
ファイル: loadtest.py プロジェクト: xinhen/asyncio-pool
async def loadtest_spawn_n(tasks, pool_size, duration):
    futures = []
    async with AioPool(size=pool_size) as pool:
        for i in range(tasks):
            fut = await pool.spawn_n(aio.sleep(duration))
            futures.append(fut)

    return [getres.flat(f) for f in futures]
コード例 #3
0
async def test_spawn_n():
    todo = range(5)
    futures = []
    async with AioPool(size=2) as pool:
        for i in todo:
            ctx = (pool, i)
            fut = pool.spawn_n(wrk(i), cb, ctx)
            futures.append(fut)

    results = [getres.flat(f) for f in futures]
    assert all(isinstance(e, ZeroDivisionError) for e in results[:2])
    assert sum(results[2:]) == 2 * (sum(todo) - 0 - 1)