close

[Solved] RuntimeError: asyncio.run() cannot be called from a running event loop

Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to use asyncio But I am facing following error RuntimeError: asyncio.run() cannot be called from a running event loop in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How this Error Occurs ?

I am trying to use asyncio But I am facing following error.

RuntimeError: asyncio.run() cannot be called from a running event loop

How To Solve RuntimeError: asyncio.run() cannot be called from a running event loop Error ?

  1. How To Solve RuntimeError: asyncio.run() cannot be called from a running event loop Error ?

    To Solve RuntimeError: asyncio.run() cannot be called from a running event loop Error You need to Use asyncio like this. import asyncio async def main(): print(1) asyncio.run(main()) This will run without error. Second solution Just use nest_asyncio.

  2. RuntimeError: asyncio.run() cannot be called from a running event loop

    To Solve RuntimeError: asyncio.run() cannot be called from a running event loop Error You need to Use asyncio like this. import asyncio async def main(): print(1) asyncio.run(main()) This will run without error. Second solution Just use nest_asyncio.

Solution 1: Use asyncio like this

You need to Use asyncio like this.

import asyncio

async def main():
    print(1)
    
asyncio.run(main())

This will run without error.

Solution 2: Use nest_asyncio

Just use nest_asyncio Here is example.

import nest_asyncio
nest_asyncio.apply()

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment