Skip to content
Discussion options

You must be logged in to vote

Hi @PeaceES

So for Azure AI Agents with Streamlit’s synchronous runtime. The event loop is closed error typically stems from Streamlit reusing or prematurely closing the loop across reruns or threaded callbacks.

Here's a distilled pattern that’s been shown to work more reliably:

Recommended Pattern: Isolated Event Loop Execution

Use a dedicated event loop per async call, and catch loop closure errors gracefully.

import asyncio

def run_async_task(coro, *args):
    try:
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        return loop.run_until_complete(coro(*args))
    except RuntimeError as e:
        # Retry with fresh loop if closed
        loop = asyncio.n…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@amynic
Comment options

Answer selected by amynic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment