Skip to content

WASM support #3311

Open
Open

Description

@A5rocks

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.

Activity

  1. CoolCat467 commented on Aug 4, 2025

    @CoolCat467
    Member

    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

  2. davidbrochart commented on Aug 4, 2025

    @davidbrochart

    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.

  3. A5rocks commented on Aug 7, 2025

    @A5rocks
    ContributorAuthor

    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.

  4. A5rocks commented on May 23, 2026

    @A5rocks
    ContributorAuthor

    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:

    pyodide.runPython(`
    import trio
    
    async def main():
      await trio.sleep(1)
      return 5
    
    print(trio.run(main))`)

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions