# RuntimeError: no running event loop

- **ID:** `python/fastapi-background-task-event-loop`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

asyncio.get_event_loop() or loop.run_until_complete() is called inside a sync background task or thread where no loop is running.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Make the background task async:
async def task(): await do_work()
background_tasks.add_task(task)
   ```
2. **** (82% success)
   ```
   In a thread, use asyncio.run(coro()) for self-contained work.
   ```

## Dead Ends

- **** — Creates leaks and doesn't share the server loop; resources bound to another loop fail. (75% fail)
- **** — Blocks the loop and doesn't address the missing loop in the thread. (80% fail)
