aiojobs

import asyncio
import aiojobs


async def coro(timeout):
    print(timeout)
    await asyncio.sleep(timeout)
    print(">>>>>>>")


async def main():
    scheduler = await aiojobs.create_scheduler()
    for i in range(1,100):
        # spawn jobs
        await scheduler.spawn(coro(i/10))

    await asyncio.sleep(4)
    # 并不是所以的工作完成

    # 优雅的结束
    await scheduler.close()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

  

posted @ 2019-03-21 16:12  公众号python学习开发  阅读(472)  评论(0编辑  收藏  举报