RuntimeError: This event loop is already running报错解决

报错内容:

错误 RuntimeError: This event loop is already running具体内容如下。


  File "D:\anaconda3\lib\site-packages\uvicorn\main.py", line 393, in run
    server.run()

  File "D:\anaconda3\lib\site-packages\uvicorn\server.py", line 50, in run
    loop.run_until_complete(self.serve(sockets=sockets))

  File "D:\anaconda3\lib\asyncio\base_events.py", line 592, in run_until_complete
    self._check_running()

  File "D:\anaconda3\lib\asyncio\base_events.py", line 552, in _check_running
    raise RuntimeError('This event loop is already running')

报错原因:

参考链接: 最后一段,讲的很细.

解决办法:

安装 pip3 install nest_asyncio,并在代码开头加入以下两行代码。

import nest_asyncio
nest_asyncio.apply()

你可能感兴趣的:(fastapi,nest_asyncio,python,jupyter)