# RuntimeError: Task <Task pending> got Future <Future pending> attached to a different loop

- **ID:** `python/asyncio-future-attached-to-loop`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A coroutine or task awaits a Future that belongs to a different event loop, often due to mixing loops across threads or using asyncio.gather with tasks from different loops.

## Version Compatibility

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

## Workarounds

1. **Ensure all coroutines and futures are created in the same event loop** (90% success)
   ```
   loop = asyncio.new_event_loop(); asyncio.set_event_loop(loop); loop.run_until_complete(main())
   ```
2. **Use asyncio.run() to avoid loop conflicts entirely** (95% success)
   ```
   async def main(): await asyncio.gather(coro1(), coro2()); asyncio.run(main())
   ```

## Dead Ends

- **Creating a new loop and setting it globally** — The Future is still attached to the original loop; global setting does not migrate it. (60% fail)
- **Using asyncio.ensure_future instead of create_task** — ensure_future also attaches to the current loop; same issue. (70% fail)
