Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Error using ib_insync with Streamlit.io - 'There is no current event loop' #563

Closed
d416 opened this issue Mar 4, 2023 · 2 comments
Closed

Comments

@d416
Copy link

d416 commented Mar 4, 2023

There is a whole thread of people trying to get ib_insync to work within Streamlit without success. Error is 'There is no current event loop.'
streamlit/streamlit#744

Maybe we can get a code recipe for doing this in the ib_insync docs? (hopefully it's this simple)

@Anton-Filimoncev
Copy link

Anton-Filimoncev commented Mar 25, 2023

Add this code before import ib_insync:

import asyncio

def get_or_create_eventloop():
    try:
        return asyncio.get_event_loop()
    except RuntimeError as ex:
        if "There is no current event loop in thread" in str(ex):
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            return asyncio.get_event_loop()

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

@erdewit
Copy link
Owner

erdewit commented Apr 2, 2023

This is not specific to ib_insync but to any asyncio application.

@erdewit erdewit closed this as completed Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants