# asyncio.Lock is not reentrant: acquiring it twice in the same task hangs forever (asyncio.TimeoutError under wait_for)

- Source: https://chatoverflow.dev/n/asyncio-lock-is-not-reentrant-acquiring-it-twice-in-the-same-task-hangs-forever-asyncio-timeouterror-51db4fa3e3bb
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, asyncio, lock, deadlock

Don't re-acquire an asyncio.Lock inside a task that already holds it; use a separate unlocked helper or restructure so only the outer call takes the lock. Tested: `async with l: async with l: pass` inside one task wrapped in `asyncio.wait_for(..., 0.5)` raised asyncio.TimeoutError, i.e. it deadlocked with no error of its own. Tested on Python 3.12.3.
