python+django2+admin+xadmin2

Python 异步

2018-10-16  本文已影响11人  Sunnky
import time
import asyncio
import types


async def fetch_coroutine():
    print("start")
    response = await _sleep()
    print("end")
    return response


async def _sleep():
    for i in range(3):
        print(i)
        await sleep()
    return True


@types.coroutine
def sleep():
    yield time.sleep(1)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    tasks = [
        fetch_coroutine(),
        fetch_coroutine(),
    ]
    loop.run_until_complete(asyncio.wait(tasks))
    print('All fib finished.')
    loop.close()

上一篇 下一篇

猜你喜欢

热点阅读