问题:在jupyter notebook中使用asyncio.run()时发生如上标题报错,没错就是这个

【Jupyter】异步RuntimeError: asyncio.run() cannot be called from a running event loop

 

 官方文档:This function cannot be called when another asyncio event loop is running in the same thread.

百度翻译:当另一个异步事件循环在同一线程中运行时,无法调用此函数

 

大致就是jupyter 已经运行了loop,无需自己激活,采用上文中的await()调用即可

In jupyter

async def main():
        print(1)
await main()

In plain Python (≥3.7)

import asyncio
async def main():
    print(1)
asyncio.run(main())

链接: 原文

参考:https://blog.csdn.net/sunnydarkcloud/article/details/101775608

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-28
  • 2022-12-23
  • 2021-08-28
  • 2021-11-21
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案