trio icon indicating copy to clipboard operation
trio copied to clipboard

WASM support

Open A5rocks opened this issue 4 months ago • 3 comments

To be concrete: support for the emscripten build of CPython and pyodide.

It would be really cool :3

I mean, it would also indicate that our basic IO manager protocol is good enough to stabilize if we can implement such a strange architecture.

I'm not sure how testing would work nor whether anyone would use it. Also I'm not sure concretely what we can support:

  • obviously we can manage sleeping and rescheduling
  • sockets isn't possible AFAIK? I guess there's those WASI things.
  • does pyodide provide a virtual file system or something? Maybe WASI does?

Unless... Trio already works due to some compatibility things done by CPython? I am 95% it doesn't work though. At least I should figure out how tests would work.

A5rocks avatar Aug 04 '25 19:08 A5rocks

On https://pyodide.org/en/stable/console.html (had to hack the script to use v0.28.0 instead of 0.28.1)

>>> import micropip
>>> await micropip.install("trio")
>>> import trio
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/lib/python3.13/site-packages/trio/__init__.py", line 22, in <module>
    from ._core import TASK_STATUS_IGNORED as TASK_STATUS_IGNORED  # isort: split
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.13/site-packages/trio/_core/__init__.py", line 21, in <module>
    from ._local import RunVar, RunVarToken
  File "/lib/python3.13/site-packages/trio/_core/_local.py", line 9, in <module>
    from . import _run
  File "/lib/python3.13/site-packages/trio/_core/_run.py", line 3004, in <module>
    raise NotImplementedError("unsupported platform")
NotImplementedError: unsupported platform

So kind of success so far, can install at least, but needs work of course

CoolCat467 avatar Aug 04 '25 19:08 CoolCat467

Maybe you just want to run a trio event loop on its own as a first step, but it's worth mentioning that pyodide integrates asyncio into the JavaScript event loop here. That allows e.g. JavaScript to await a Python task.

davidbrochart avatar Aug 04 '25 20:08 davidbrochart

I would expect we don't need any special support in pyodide because of trio.lowlevel.wait_task_rescheduled (for Python awaiting JS) and the other way around is probably simple to do with plain JS promises.


So kind of success so far, can install at least, but needs work of course

Yeah, I think that means we don't have an IO manager for it.

A5rocks avatar Aug 07 '25 04:08 A5rocks