Tag Archives: Asynchronous co process

[Solved] Python Error: asyncio RuntimeError: This event loop is already running

In case of an error, the following diagram is given:

Solution:

# download nest_asyncio
pip3 install nest_asyncio

Add the following two lines at the beginning of the asynchronous collaboration code, or in the code:

import nest_asyncio

nest_asyncio.apply()

After consulting the data, it is found that using the Jupiter notebook environment, it is connected to the IPython kernel, and the IPython kernel itself runs on the event loop, while asyncio does not allow nesting of its event loop, so the error message as shown in the above figure will appear.

nest_asyncio exists as a patch for asynchronous operations.