美文网首页
Jupyter中asyncio.run() cannot be

Jupyter中asyncio.run() cannot be

作者: _咚咚咚东 | 来源:发表于2020-01-16 22:01 被阅读0次

    问题:

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

    相关文章

      网友评论

          本文标题:Jupyter中asyncio.run() cannot be

          本文链接:https://www.haomeiwen.com/subject/smyqzctx.html