asyncio 模块

import asyncio


async def hello():
    print('Hello start!')
    await asyncio.sleep(2)
    print('Hello end!')


async def hello222():
    print('Hello222 start!')
    result = await somework()
    print('Hello222 end', result)


async def somework():
    print('somework start...')
    await asyncio.sleep(3)
    print("somework     end ")
    return ("sleep 3 s")


loop = asyncio.get_event_loop()
tasks = [hello(), hello222()]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()

  

posted @ 2018-04-14 13:19  qukaige  阅读(139)  评论(0编辑  收藏  举报