Skip to content

Commit

Permalink
fix: subclasses cannot access name-mangled mangled loop attr (#436)
Browse files Browse the repository at this point in the history
* feat: speed up SmartTask and SmartFuture init

* fix: cannot access name-mangled __loop
  • Loading branch information
BobTheBuidler authored Nov 23, 2024
1 parent 8a8ee41 commit 54b2f8e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions a_sync/_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import asyncio
import contextvars
import logging
import warnings
import weakref
Expand Down Expand Up @@ -197,7 +198,7 @@ def __init__(
if key:
self._key = key
self._waiters = weakref.WeakSet()
self.add_done_callback(SmartFuture._self_done_cleanup_callback)
self._callbacks.append((SmartFuture._self_done_cleanup_callback, contextvars.copy_context()))

def __repr__(self):
return f"<{type(self).__name__} key={self._key} waiters={self.num_waiters} {self._state}>"
Expand Down Expand Up @@ -298,7 +299,7 @@ def __init__(
"""
asyncio.Task.__init__(self, coro, loop=loop, name=name)
self._waiters: Set["asyncio.Task[T]"] = set()
self.add_done_callback(SmartTask._self_done_cleanup_callback)
self._callbacks.append((SmartTask._self_done_cleanup_callback, contextvars.copy_context()))


def smart_task_factory(
Expand Down
2 changes: 1 addition & 1 deletion a_sync/primitives/locks/prio_semaphore.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ cdef class _AbstractPrioritySemaphoreContextManager(Semaphore):
while self._parent._Semaphore__value <= 0:
if self._AbstractPrioritySemaphoreContextManager__waiters is None:
self._AbstractPrioritySemaphoreContextManager__waiters = deque()
fut = (self.__loop or self._c_get_loop()).create_future()
fut = self._c_get_loop().create_future()
self._AbstractPrioritySemaphoreContextManager__waiters.append(fut)
self._parent._potential_lost_waiters.append(fut)
try:
Expand Down

0 comments on commit 54b2f8e

Please sign in to comment.