You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Condition.notify() fails when shared lock is held #1319
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
AnyIO version
4.14
Python version
3.11
What happened?
When using a Condition with an existing lock, it's not possible to call notify(...) unless the lock was acquired via the condition.
This makes it difficult to use multiple conditions which share the same lock (i.e., when different types of waiter depend on the same underlying state).
For example:
asyncwithself._lock:
mutate_state()
ifpending_changed:
# !! RuntimeError: The current task is not holding the underlying lock.self._pending_condition.notify()
ifready_changed:
self._ready_condition.notify()
To work around this, I think the only solutions would be to:
a. Use a single condition to notify every waiter of every change
b. Acquire and release the lock twice, losing the atomicity of the state change and the notifications
Activity