. Advertisement .
..3..
. Advertisement .
..4..
Hi everyone, I’m learning about python. While working, I try calls asyncio.get_event_loop().run_until_complete(foo()) twice. Once from foo() and second time from function called by foo(). As a result, I get the message:
RuntimeError: This event loop is already running in python
What can I do about the “runtimeerror this event loop is already running” issue? Is there a better approach?
The cause: You might have a misunderstanding about how asyncio works because Event loop running – is an entry point of your async program. It oversees the execution of all coroutines, tasks, and callbacks. Running a loop while it’s running makes no sense: it’s like trying to run a job executor from a job executor that’s already running.
The solution: You can fix this issue by using nest_async or asyncio
Solution #1
Simply follow these steps to install the package:
Then add the following lines:
Solution #2
If nest asyncio isn’t working, try using asyncio:
The nest_async solved the problem.
Add the following lines to my file