文章目录
- 问题描述
- 解决方案
- 参考文献
问题描述
import asyncioasync 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())
参考文献
- asyncio — 异步 I/O