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
asyncio: Inconsistent lazy initialization of _waiters in Event and Condition #148489
Lock and Semaphore use lazy initialization for their _waiters deque (initialized to None, allocated on first contention), while Event and Condition eagerly allocate collections.deque() in __init__.
The lazy pattern was introduced for Lock and later applied to Semaphore in GH-97545 ("Make Semaphore run faster", merged by @gvanrossum). The same optimization was not applied to Event and Condition.
Impact
Consistency: Four synchronization primitives in the same module use two different initialization patterns for the same data structure.
Performance: Creating an Event or Condition that never gets waited on incurs an unnecessary collections.deque() allocation (~42ns per creation, ~13x slower than None assignment on the init path).
Maintenance: The inconsistency means contributors working on one primitive may not realize the other primitives follow a different pattern.
Proposed fix
Apply the same lazy initialization to Event and Condition:
Initialize _waiters = None in __init__
Allocate collections.deque() on first wait() call
Add null guards in set(), _notify(), and notify_all()
Activity
pythongh-148489: Lazy-init _waiters in asyncio Event and Condition
sergey-miryanov commentedon Apr 13, 2026
It is an AI generated issues and PR. I closed PR now, and add pending label here.
sergey-miryanov commentedon Apr 13, 2026
cc @kumaraditya303