当前位置: 代码迷 >> 综合 >> AttributeError: module ‘asyncio‘ has no attribute ‘run‘
  详细解决方案

AttributeError: module ‘asyncio‘ has no attribute ‘run‘

热度:26   发布时间:2024-02-04 12:32:29.0

文章目录

  • 问题描述
  • 解决方案
  • 参考文献

问题描述

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())




参考文献

  1. asyncio — 异步 I/O
  相关解决方案