# RuntimeError: no running event loop

- **ID:** `python/no-running-event-loop`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

asyncio.get_running_loop() (or an API that calls it internally, like asyncio.create_task) was invoked from synchronous code outside any running loop.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Only call create_task/get_running_loop from inside a coroutine:

async def main():
    asyncio.create_task(worker())

asyncio.run(main())
   ```
2. **** (85% success)
   ```
   From sync code that must schedule work, use asyncio.run_coroutine_threadsafe when you have a loop reference:

future = asyncio.run_coroutine_threadsafe(coro(), loop)
   ```
3. **** (80% success)
   ```
   In Jupyter/IPython, use `await` directly in the cell, or call nest_asyncio.apply() once at the top of the notebook.
   ```

## Dead Ends

- **** — Deprecated since 3.10 and emits DeprecationWarning; in 3.12 it still raises when no loop is set. (55% fail)
- **** — Makes it worse — guarantees no loop is available. (95% fail)
- **** — Timing has nothing to do with loop presence. (90% fail)
