{
  "id": "python/asyncio-lock-acquire-timeout",
  "signature": "asyncio.exceptions.TimeoutError: Lock acquire timed out",
  "signature_zh": "asyncio 异常：锁获取超时",
  "regex": "asyncio\\.exceptions\\.TimeoutError:\\ Lock\\ acquire\\ timed\\ out",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A coroutine tried to acquire an asyncio.Lock with a timeout, but the lock was not released within that time.",
  "root_cause_type": "generic",
  "root_cause_zh": "协程尝试使用超时获取 asyncio.Lock，但锁未在指定时间内释放。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increasing the timeout indefinitely",
      "why_fails": "This may cause the application to hang if the lock is never released.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a try-finally block without ensuring release on cancellation",
      "why_fails": "If the coroutine is cancelled, the lock may not be released, causing deadlocks.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use async with for lock to ensure automatic release",
      "success_rate": 0.95,
      "how": "async with lock:\n    # critical section",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement a retry mechanism with backoff",
      "success_rate": 0.85,
      "how": "async def acquire_with_retry(lock, timeout=5):\n    for i in range(3):\n        try:\n            await asyncio.wait_for(lock.acquire(), timeout=timeout)\n            return\n        except asyncio.TimeoutError:\n            await asyncio.sleep(1)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-12-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}