Skip to content

asyncio.run() cannot be called from a running event loop #924

Answered by dosubot bot
SixJohn asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @SixJohn, I'm here to assist you with any bugs, questions, or contributions you have. Let's work together to solve this issue!

The error "asyncio.run() cannot be called from a running event loop" occurs when you try to use asyncio.run() inside an already running event loop. This is common in environments like Jupyter notebooks or certain web frameworks.

To resolve this, you can use an alternative approach to run your asynchronous functions. Instead of asyncio.run(), you can use await directly if you're in an async function, or use asyncio.create_task() or asyncio.gather() to manage your coroutines. Here's a basic example of how you might adjust your code:

import asyncio

async def main

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by SixJohn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant