問題:在jupyter notebook中使用asyncio.run()時發生如上標題報錯,沒錯就是這個
官方文檔: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