-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PEP 776: Emscripten support #4307
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PEP and work on Emscripten! I've edited the top post with the new PEP checklist, please could you work through it and check things off? You can use PEP number 776. |
What form does this formal confirmation take? Comment here? cc @ambv @freakboy3742. |
The preview link shows pep-0776 as a 404 for me: https://pep-previews--4307.org.readthedocs.build/pep-0776/ |
Lowercase name seemed to be the problem. |
Revert 871a223 but keep the newline before the bullet list: WebAssembly does not have native support for signals. Furthermore, on a
non-pthreads build, the address space of the WebAssembly module is not shared,
so it is impossible for any thread capable of seeing an interrupt to write to
the eval breaker while the Python interpreter is running code. To work around
this, there are two possible solutions:
* If Emscripten is run in a webworker and served with the shared memory headers,
it is possible to use shared memory outside of the WebAssembly address space
as a signal buffer. A signal handling UI thread can write the desired signal
into the signal buffer. The interpreter can periodically check the state of
this signal buffer in the eval breaker code. Checking the signal buffer is
slow compared to checking the eval breaker in native platforms, so we do only
do it once every 50 times through the eval breaker. See
`Python/emscripten_signal.c <https://github.com/python/cpython/blob/2bef8ea8ea045d20394f0daec7a5c5b1046a4e22/Python/emscripten_signal.c>`__
* Using stack switching, we can occasionally switch the stack and allow the
JavaScript event loop to go around, then check the state of a signal buffer.
This requires the experimental JavaScript Promise Integration API, and would
be best used with the techniques for optimizing long tasks described
`in this article <https://web.dev/articles/optimize-long-tasks>`__
Emscripten Python has already implemented the solution based on shared memory,
and it is in use in Pyodide. |
I formally confirm sponsorship. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @hoodmane !
I'm not sure about PEP review process, and if you would rather not get comments here, sorry about that.
Still a few comment below :)
``pyodide_<abi>`` and ``emscripten_<version>`` is intended to be the same as the | ||
relationship between ``manylinux<version>`` and ``linux``. | ||
|
||
The specification of the ``pyodide_<abi>`` ABI includes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if there was a link to some page where these ABI versions are going to be tracked maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been meaning to add to Pyodide a policies
page, which would be a good place to refer to for this. I think the most contentious part of this PEP is likely to be who/what organization chooses the ABI and what it is called...
These wording comments are generally fine here, thanks. This first review is mainly for structure and formatting. Once merged, the PEP will be discussed in depth with the community on discuss.python.org (should we do this, how should we do it, etc). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hoodmane Ping when you're ready to merge.
Co-authored-by: Hugo van Kemenade <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some editorial comments.
|
||
as well as any functionality that requires these. | ||
|
||
The following are present but cannot be imported due to a dependency on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So why aren't they removed too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh... that is a good question. This language was added to the Pyodide docs in this PR:
pyodide/pyodide#4078
I just confirmed is true of both Pyodide and Emscripten Cpython. I think the removals are mainly targeted at large modules whereas pty and tty are only a few kilobytes so nobody ever bothered to remove them. If we think they should be removed, I can add language to that effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I don't feel strongly, this just stood out as an oddity while reading
Co-authored-by: Jelle Zijlstra <[email protected]>
Thanks for the copy edit @JelleZijlstra! |
Co-authored-by: Adam Turner <[email protected]>
This reverts commit 0a8d64e.
@hugovk I think this can be merged now. I will address the remaining feedback in followup PRs. Thanks everyone! |
Co-authored-by: Brett Cannon <[email protected]>
@AA-Turner I saw you are intending to review, but I'd rather merge this now since Hugo and I already approved and I prefer for PEPs not to get stuck in the ready-but-not-yet-merged state. If you have feedback, we can always update the PEP text later. |
I'm about halfway through (mainly editorial points, but nothing major so far). Happy for you to merge now though. I agree we should avoid PEPs being "ready but not merged" (several have been as drafts in PRs for days/weeks(!)), but this PR was only opened this morning -- I had an unexpectedly busy day, so was late on a full read-through. A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hoodmane. Very well written and happy to see this continue to move forward. I remember the early days of pyodide and iodide at Mozilla.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry again for the delay, almost entirely editorial points.
run in JavaScript runtimes including browsers and Node.js. | ||
|
||
This PEP formalizes the addition of Tier 3 for Emscripten support in Python 3.14 | ||
which `was approved by the steering council on October 25, 2024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which `was approved by the steering council on October 25, 2024 | |
which `was approved by the Steering Council on October 25, 2024 |
This PEP formalizes the addition of Tier 3 for Emscripten support in Python 3.14 | ||
which `was approved by the steering council on October 25, 2024 | ||
<https://github.com/python/steering-council/issues/256>`__. The goal is to allow | ||
Pyodide wheels to be uploaded to PyPI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pyodide (or the relationship to Emscripten) isn't defined here, perhaps a link?
`Emscripten <https://emscripten.org/>`__ is a complete open source compiler | ||
toolchain which compiles C/C++ code into WebAssembly/JavaScript executables that | ||
run in JavaScript runtimes including browsers and Node.js. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence read a little breathlessly. I also would suggest removing the paragraph break afterwards.
Also, later on the PEP mentions the "Rust emscripten target" -- is this part of the emscripten project? Should the support for Rust/non-C native languages be mentioned here?
`Emscripten <https://emscripten.org/>`__ is a complete open source compiler | |
toolchain which compiles C/C++ code into WebAssembly/JavaScript executables that | |
run in JavaScript runtimes including browsers and Node.js. | |
`Emscripten <https://emscripten.org/>`__ is a complete open source compiler | |
toolchain. It compiles C/C++ code into WebAssembly/JavaScript executables, | |
for use in JavaScript runtimes, including browsers and Node.js. |
`Emscripten | ||
<https://emscripten.org/docs/introducing_emscripten/about_emscripten.html>`__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional, throughout: To use intersphinx (would need corresponding definition in conf.py
)
`Emscripten | |
<https://emscripten.org/docs/introducing_emscripten/about_emscripten.html>`__ | |
:ref:`Emscripten <emscripten:about-emscripten>` |
Linux, and every smartphone. | ||
|
||
`The Pyodide project <https://pyodide.org/>`__ has for years supported | ||
Emscripten Python. Hundreds of thousands of students have learned Python through |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read a couple of times and I'm unclear on the distinction between "Emscripten Python" and "Pyodide". Is there a reference for a disambiguation? The only mention of Python on the emscripten intro page references Pyodide.
1. To describe Pyodide's packaging tooling | ||
2. To describe Pyodide's wheel abi to a similar level of detail as the manylinux | ||
PEPs | ||
3. To request that Pyodide wheels be allowed for upload to PyPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A PEP specifies, rather than requesting -- if this PEP is accepted and implemented, Pyodide wheels will be permitted:
3. To request that Pyodide wheels be allowed for upload to PyPI | |
3. For Pyodide wheels to be allowed for upload to PyPI |
Emscripten is a POSIX-based platform. It uses the WebAssembly binary format, | ||
specified here: | ||
|
||
* https://webassembly.github.io/spec/core/binary/index.html | ||
* https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an accurate rephrasing?
Emscripten is a POSIX-based platform. It uses the WebAssembly binary format, | |
specified here: | |
* https://webassembly.github.io/spec/core/binary/index.html | |
* https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md | |
Emscripten is a POSIX-based platform. It uses the `WebAssembly binary format`_, | |
including the `dynamic linking extension`_. | |
.. _WebAssembly binary format: https://webassembly.github.io/spec/core/binary/index.html | |
.. _dynamic linking extension: https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md |
Because of these limitations, Pyodide standardizes a no-pthreads build of | ||
Python. We will start with support for no-pthreads builds. If there is | ||
sufficient demand, a pthreads build with no dynamic loader could be added later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second sentence seems to repeat the first
Because of these limitations, Pyodide standardizes a no-pthreads build of | |
Python. We will start with support for no-pthreads builds. If there is | |
sufficient demand, a pthreads build with no dynamic loader could be added later. | |
Because of these limitations, Pyodide standardizes a no-pthreads build of | |
Python. If there is sufficient demand, a pthreads build with no dynamic loader | |
could be added later. |
Packages | ||
~~~~~~~~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Packages | |
~~~~~~~~ | |
Third-party packages | |
~~~~~~~~~~~~~~~~~~~~ |
Basic requirements (all PEP Types)
pep-NNNN.rst
), PR title (PEP 123: <Title of PEP>
) andPEP
headerAuthor
orSponsor
, and formally confirmed their approvalAuthor
,Status
(Draft
),Type
andCreated
headers filled out correctlyPEP-Delegate
,Topic
,Requires
andReplaces
headers completed if appropriate.github/CODEOWNERS
for the PEPStandards Track requirements
Python-Version
set to valid (pre-beta) future Python version, if relevantDiscussions-To
andPost-History
📚 Documentation preview 📚: https://pep-previews--4307.org.readthedocs.build/pep-0776/