Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions wgpu/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@

logger = logging.getLogger("wgpu")

IS_PYODIDE = sys.platform == "emscripten"


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:
Expand All @@ -29,6 +35,10 @@ def detect_current_async_lib():
def detect_current_call_soon_threadsafe():
"""Get the current applicable call_soon_threadsafe function, or None"""

# Pyodide always runs asyncio (which wraps the JS native event loop)
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:
Expand Down