diff --git a/examples/demo.py b/examples/demo.py index fa44aa9..07fe305 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -16,7 +16,7 @@ import time -from rendercanvas.glfw import RenderCanvas, loop +from rendercanvas.auto import RenderCanvas, loop from rendercanvas.utils.cube import setup_drawing_sync from rendercanvas.utils.asyncs import sleep diff --git a/rendercanvas/_loop.py b/rendercanvas/_loop.py index ad7949e..54b4f75 100644 --- a/rendercanvas/_loop.py +++ b/rendercanvas/_loop.py @@ -7,7 +7,7 @@ from ._coreutils import logger, log_exception from .utils.asyncs import sleep -from ._async_adapter import Task as AsyncAdapterTask +from .utils import asyncadapter HANDLED_SIGNALS = ( @@ -338,7 +338,7 @@ def _rc_add_task(self, async_func, name): * The subclass is responsible for cancelling remaining tasks in _rc_stop. * Return None. """ - task = AsyncAdapterTask(self, async_func(), name) + task = asyncadapter.Task(self._rc_call_later, async_func(), name) self.__tasks.add(task) task.add_done_callback(self.__tasks.discard) diff --git a/rendercanvas/_async_adapter.py b/rendercanvas/utils/asyncadapter.py similarity index 94% rename from rendercanvas/_async_adapter.py rename to rendercanvas/utils/asyncadapter.py index 0d23c12..80461b3 100644 --- a/rendercanvas/_async_adapter.py +++ b/rendercanvas/utils/asyncadapter.py @@ -7,7 +7,7 @@ from sniffio import thread_local as sniffio_thread_local -logger = logging.getLogger("rendercanvas") +logger = logging.getLogger("asyncadapter") class Sleeper: @@ -62,12 +62,12 @@ class CancelledError(BaseException): class Task: """Representation of task, exectuting a co-routine.""" - def __init__(self, loop, coro, name): - self.loop = loop + def __init__(self, call_later_func, coro, name): + self._call_later = call_later_func + self._done_callbacks = [] self.coro = coro self.name = name self.cancelled = False - self._done_callbacks = [] self.call_step_later(0) def add_done_callback(self, callback): @@ -81,9 +81,10 @@ def _close(self): callback(self) except Exception: pass + self._done_callbacks.clear() def call_step_later(self, delay): - self.loop._rc_call_later(delay, self.step) + self._call_later(delay, self.step) def cancel(self): self.cancelled = True