`RuntimeError: asyncio.run() cannot be called from a running event loop` in a Jupyter notebook or inside an async framework.
IntermediateTroubleshootingConcurrency, async, tests, services & containers
Answer
Likely causes → An event loop is already running (Jupyter, FastAPI, another asyncio.run caller), and asyncio.run tries to start a new one.
Diagnose → Check whether the calling code is itself inside a coroutine or a notebook cell.
Fix → In Jupyter, use top-level await main(). Inside async code, await the coroutine or asyncio.create_task(...) instead of calling asyncio.run. From sync code in another thread, use asyncio.run_coroutine_threadsafe(coro, loop).
Prevent → Only call asyncio.run once, at the program's entry point.
More on Concurrency, async, tests, services & containers
`RuntimeWarning: coroutine 'fetch' was never awaited` and nothing happens.BeginnerAn asyncio health-checker is no faster than a sequential loop.Advanced`Task was destroyed but it is pending!` at shutdown.Advanced`OSError: [Errno 24] Too many open files` from an asyncio scanner with 20,000 targets.IntermediateA `ThreadPoolExecutor` job finishes "successfully" but half the work is missing, with no errors logged.IntermediateIntermittent `KeyError: 'credential_provider'` or `KeyError: 'endpoint_resolver'` when creating boto3 clients from many threads.Advanced