Skip to content

Commit

Permalink
fix: cannot access name-mangled __loop (#437)
Browse files Browse the repository at this point in the history
* fix: accidental commit

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

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

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


def smart_task_factory(
Expand Down
16 changes: 8 additions & 8 deletions a_sync/primitives/_debug.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cdef object _get_running_loop():

cdef class _LoopBoundMixin(_LoggerMixin):
def __cinit__(self):
self.__loop = None
self._LoopBoundMixin__loop = None
def __init__(self, *, loop=None):
if loop is not None:
raise TypeError(
Expand All @@ -42,25 +42,25 @@ cdef class _LoopBoundMixin(_LoggerMixin):
)
@property
def _loop(self) -> asyncio.AbstractEventLoop:
return self.__loop
return self._LoopBoundMixin__loop
@_loop.setter
def _loop(self, loop: asyncio.AbstractEventLoop):
self.__loop = loop
self._LoopBoundMixin__loop = loop
cpdef object _get_loop(self):
return self._c_get_loop()
cdef object _c_get_loop(self):
cdef object loop = _get_running_loop()
if self.__loop is None:
if self._LoopBoundMixin__loop is None:
with _global_lock:
if self.__loop is None:
self.__loop = loop
if self._LoopBoundMixin__loop is None:
self._LoopBoundMixin__loop = loop
if loop is None:
return get_event_loop()
elif loop is not self.__loop:
elif loop is not self._LoopBoundMixin__loop:
raise RuntimeError(
f'{self!r} is bound to a different event loop',
"running loop: ".format(loop),
"bound to: ".format(self.__loop),
"bound to: ".format(self._LoopBoundMixin__loop),
)
return loop

Expand Down

0 comments on commit 9f8fbaa

Please sign in to comment.