How to use asyncio in streamlit app?

Error:

File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)File "/app/virtual_home_decorator_app/app.py", line 135, in <module>
    asyncio.get_event_loop().run_until_complete(main())File "/usr/local/lib/python3.9/asyncio/events.py", 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”:
asyncio.get_event_loop().run_until_complete(main())

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

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.