diff --git a/rendercanvas/_coreutils.py b/rendercanvas/_coreutils.py index ae9c20a..c39a626 100644 --- a/rendercanvas/_coreutils.py +++ b/rendercanvas/_coreutils.py @@ -19,6 +19,7 @@ IS_WIN = sys.platform.startswith("win") # Note that IS_WIN is false on Pyodide +IS_PYODIDE = sys.platform == "emscripten" # %% Logging diff --git a/rendercanvas/utils/asyncs.py b/rendercanvas/utils/asyncs.py index 5d399b0..0ddb592 100644 --- a/rendercanvas/utils/asyncs.py +++ b/rendercanvas/utils/asyncs.py @@ -12,7 +12,7 @@ import sys -from .._coreutils import IS_WIN, call_later_from_thread +from .._coreutils import IS_WIN, IS_PYODIDE, call_later_from_thread USE_THREADED_TIMER = IS_WIN @@ -24,6 +24,10 @@ def detect_current_async_lib(): """Get the lib name of the currently active async lib, or None.""" + + if IS_PYODIDE: + return "asyncio" + ob = sys.get_asyncgen_hooks()[0] if ob is not None: try: @@ -40,6 +44,10 @@ def detect_current_async_lib(): def detect_current_call_soon_threadsafe(): """Get the current applicable call_soon_threadsafe function, or None""" + # We could support Pyodide too, but this never gets called on Pyodide anyway (bc USE_THREADED_TIMER). Leaving commented for reference. + # if IS_PYODIDE: + # return sys.modules["asyncio"].get_running_loop().call_soon_threadsafe + # Get asyncgen hook func, return fast when no async loop active ob = sys.get_asyncgen_hooks()[0] if ob is None: diff --git a/tests/test_glfw.py b/tests/test_glfw.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_scheduling.py b/tests/test_scheduling.py index 762044c..fe11106 100644 --- a/tests/test_scheduling.py +++ b/tests/test_scheduling.py @@ -147,8 +147,8 @@ def _test_scheduling_continuous(canvas): # And a second one after 0.1s, with 10 fps. canvas.active_sleep(0.1) - assert canvas.draw_count == 2 - assert canvas.events_count == 2 + assert canvas.draw_count in (2, 3) + assert canvas.events_count in (2, 3) # And after one second, about 10 more canvas.draw_count = canvas.events_count = 0