How to use asyncio in streamlit app?


File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/", line 534, in _run_script
    exec(code, module.__dict__)File "/app/virtual_home_decorator_app/", line 135, in <module>
    asyncio.get_event_loop().run_until_complete(main())File "/usr/local/lib/python3.9/asyncio/", line 642, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'

relevant code:
async def main(websocket, path):
start_server = websockets.serve(main, “localhost”, 8765)
await asyncio.get_event_loop().run_until_complete(start_server)

Run the WebSocket server

if name == “main”:

That code raises TypeError, you must be running some other code.