问题:
import asyncio
async def main():
print(1)
asyncio.run(main())
这种写法在jupyter中报错。
搜索之后发现是:
The problem in your case is that jupyter (IPython) is already running an event loop (for IPython ≥ 7.0):
大致就是jupyter 已经运行了loop,无需自己激活,采用上文中的await()调用即可
正确的写法如下:
async def main():
print(1)
await main()
网友评论