# asyncio.exceptions.TimeoutError: Lock acquire timed out

- **ID:** `python/asyncio-lock-acquire-timeout`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A coroutine tried to acquire an asyncio.Lock with a timeout, but the lock was not released within that time.

## Version Compatibility

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

## Workarounds

1. **Use async with for lock to ensure automatic release** (95% success)
   ```
   async with lock:
    # critical section
   ```
2. **Implement a retry mechanism with backoff** (85% success)
   ```
   async def acquire_with_retry(lock, timeout=5):
    for i in range(3):
        try:
            await asyncio.wait_for(lock.acquire(), timeout=timeout)
            return
        except asyncio.TimeoutError:
            await asyncio.sleep(1)
   ```

## Dead Ends

- **Increasing the timeout indefinitely** — This may cause the application to hang if the lock is never released. (40% fail)
- **Using a try-finally block without ensuring release on cancellation** — If the coroutine is cancelled, the lock may not be released, causing deadlocks. (60% fail)
