Esempio n. 1
0
 def baz():
     task = asyncio.ensure_future(xuz())
     yield from asyncio.sleep(0.1)
     for _ in range(100):
         assert format_task_stack(task, limit=0)
         assert format_task_stack(task, limit=-300)
         assert format_task_stack(task, limit=None)
         assert format_task_stack(task, limit=3, capture_locals=True)
     yield from on_done.wait()
Esempio n. 2
0
async def test_format_task_stack():

    on_done = asyncio.Event()

    async def foo():
        await bar()

    async def bar():
        await baz()

    @asyncio.coroutine
    def baz():
        task = asyncio.ensure_future(xuz())
        yield from asyncio.sleep(0.1)
        for _ in range(100):
            assert format_task_stack(task, limit=0)
            assert format_task_stack(task, limit=-300)
            assert format_task_stack(task, limit=None)
            assert format_task_stack(task, limit=3, capture_locals=True)
        yield from on_done.wait()

    async def xuz():
        await xuz1()
        await xuz2()

    async def xuz1():
        await asyncio.sleep(1)

    async def xuz2():
        await asyncio.sleep(0.1)
        [i async for i in xuz3()]
        on_done.set()

    async def xuz3():
        for i in range(100):
            yield i

    await foo()

    task = asyncio.ensure_future(xuz2())
    await asyncio.sleep(0.05)
    assert format_task_stack(task, limit=None)

    @asyncio.coroutine
    def moo():
        yield from asyncio.sleep(0.1)

    task = asyncio.ensure_future(moo())
    await asyncio.sleep(0.05)
    assert format_task_stack(task, limit=None)