WASM support #3311
Copy link
Copy link
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
CoolCat467 commentedon Aug 4, 2025
On https://pyodide.org/en/stable/console.html (had to hack the script to use v0.28.0 instead of 0.28.1)
So kind of success so far, can install at least, but needs work of course
davidbrochart commentedon Aug 4, 2025
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.
A5rocks commentedon Aug 7, 2025
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.Yeah, I think that means we don't have an IO manager for it.
A5rocks commentedon May 23, 2026
I made a prototype version. See https://github.com/A5rocks/trio/tree/wasm-trio, you can run it via
uv run -m build && uv run -m http.server, then open http://localhost:8000 and try something like this in the console:Unfortunately, there doesn't seem to be a way to suspend execution. This makes this entirely impractical, since it means you won't be able to reschedule from e.g. promises. It's possible to work around this, but that would mean no return value from
trio.run(note: it's synchronous!).The best alternate implementation probably involves spitting a signal at the program like in https://pyodide.org/en/stable/usage/keyboard-interrupts.html but that's pyodide specific. This is all just supposed to be whimsical so I don't really think it's worth tying ourselves to a particular implementation for practical results.