RuntimeError: asyncio.run() cannot be called from a running event loop in Jupyter

Running the Hume streaming example in a Jupyter notebook failed with RuntimeError: asyncio.run() cannot be called from a running event loop because Jupyter already runs its own event loop. Maintainer gregorybchris explained the fix: merge the coroutine into Jupyter's loop instead of calling asyncio.run. The pattern is loop = asyncio.get_event_loop() followed by loop.create_task(main()). The reporter confirmed it worked.

Jupyter owns the event loop already, so asyncio.run(main()) will always fail there with this error. Replace it with loop = asyncio.get_event_loop() and loop.create_task(main()) to schedule your coroutine on Jupyter's loop. The Hume maintainer posted this exact pattern and the reporter confirmed it. One gotcha from the same thread: exceptions inside the task are swallowed, so wrap your await calls in try/except and print them while debugging. Source: https://github.com/HumeAI/hume-python-sdk/issues/40

Source: https://github.com/HumeAI/hume-python-sdk/issues/40