import asyncio
async def hello(name):
print('Hello,', name)
# 定義協程對象
coroutine = hello("World")
# 定義事件循環對象容器
loop = asyncio.get_event_loop()
# task = asyncio.ensure_future(coroutine)
# 將協程轉爲task任務
task = loop.create_task(coroutine)
# 將task任務扔進事件循環對象中並觸發
loop.run_until_complete(task)
原因是本地有一個與asyncio.py同名文件,導入的時候導入的是本地額,而不是系統的。