ib_insync
ib_insync copied to clipboard
Error using ib_insync with Streamlit.io - 'There is no current event loop'
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.' https://github.com/streamlit/streamlit/issues/744
Maybe we can get a code recipe for doing this in the ib_insync docs? (hopefully it's this simple)
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)
This is not specific to ib_insync but to any asyncio application.