美文网首页
asyncio task使用

asyncio task使用

作者: Do_More | 来源:发表于2018-07-01 10:28 被阅读0次
import asyncio, time

now = lambda : time.time()

async def do_some_work(x):
    print('waiting: ', x)

start = now()
coroutine = do_some_work(2)
loop = asyncio.get_event_loop()
task = loop.create_task(coroutine)

print(task)
loop.run_until_complete(task)
print(task)
print('time: ', now() - start)

相关文章

网友评论

      本文标题:asyncio task使用

      本文链接:https://www.haomeiwen.com/subject/fxscuftx.html