问题描述
import asyncio
async def count():
print("One")
await asyncio.sleep(1)
print("Two")
async def main():
await asyncio.gather(count(), count(), count())
asyncio.run(main())
报错 AttributeError: module 'asyncio' has no attribute 'run'
解决方案
原因一:
同文件夹下有 asyncio.py
原因二:
Python 版本低于 3.7
asyncio.run(main())
换成
asyncio.get_event_loop().run_until_complete(main())