# asyncio.exceptions.InvalidStateError: Task is not done

- **ID:** `python/asyncio-queue-task-done-never-set`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

task.result() or task.exception() was called before the task completed; both require the task to be in the DONE state.

## Version Compatibility

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

## Workarounds

1. **** (97% success)
   ```
   task = asyncio.create_task(work())
result = await task
   ```
2. **** (92% success)
   ```
   done, pending = await asyncio.wait({task}, timeout=10)
if task in done:
    print(task.result())
   ```

## Dead Ends

- **** — Arbitrary sleeps are racy; under load the task may still be pending. (80% fail)
- **** — Busy-looping until done wastes CPU and does not guarantee completion. (70% fail)
