立即学习:https://edu.youkuaiyun.com/course/play/26755/340174?utm_source=blogtoedu
协程,又称为微线程,用async修饰要运行的函数,在运行协程函数时,需要使用await。
async def say(delay,what):
await asyncio.sleep(delay)
print(what)
task1=asyncio.create_task(
say_after(1,'hello')
task2=asyncio.create_task)
say_after(2,'world') # task 并不运行,只是指定任务
await task1 # 这里运行任务
await task2
asyncio.run(say())
用run和create_task