From 51851934b358cf7cecfb148c7c18eb4eedd537b0 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 27 Oct 2026 12:17:18 -0700 Subject: [PATCH 1/5] PEP 818: Clarify that run_until_complete raises NotImplementedError for now And that we will hopefully fix this by adding stack switching in the future --- peps/pep-0818.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/peps/pep-0818.rst b/peps/pep-0818.rst index 525d8ec8cfa..57b1ce6fa23 100644 --- a/peps/pep-0818.rst +++ b/peps/pep-0818.rst @@ -76,9 +76,12 @@ CPython. .. _Emscripten-forge: https://emscripten-forge.org/ In order to keep the length of this PEP reasonable, we focus on the "core" of -the foreign function interface. The JavaScript interface for managing the Python -runtime is left to a future PEP. +the foreign function interface. The following things are left to future +proposals: +* A JavaScript interface for managing the Python interpreter lifecycle +* Stack switching support, and in particular support for blocking for the + completion of an awaitable (e.g., ``run_until_complete()``) Rationale ========= @@ -1356,6 +1359,12 @@ Promise methods ``then()``, ``catch()`` and ``finally_()``. This is so that code can work consistently regardless of whether they have a ``Promise``, a ``WebFuture`` or a ``WebTask``. +In order to implement ``run_until_complete()``, we need stack switching support +in the runtime. Downstream, Pyodide has implemented stack switching support and +``run_until_complete()`` works as expected. Until we have such stack switching +support, ``run_until_complete()`` will raise a ``NotImplementedError``. This +will most likely be the topic of a followup proposal. + Adapting from a Python awaitable to a JavaScript awaitable ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 2d10376898c4346bee4c9e89812a64731f83993e Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 27 Oct 2026 12:20:39 -0700 Subject: [PATCH 2/5] reword --- peps/pep-0818.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peps/pep-0818.rst b/peps/pep-0818.rst index 57b1ce6fa23..64bb8101532 100644 --- a/peps/pep-0818.rst +++ b/peps/pep-0818.rst @@ -1363,7 +1363,7 @@ In order to implement ``run_until_complete()``, we need stack switching support in the runtime. Downstream, Pyodide has implemented stack switching support and ``run_until_complete()`` works as expected. Until we have such stack switching support, ``run_until_complete()`` will raise a ``NotImplementedError``. This -will most likely be the topic of a followup proposal. +will be the topic of a followup proposal. Adapting from a Python awaitable to a JavaScript awaitable ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 1bf6dba246a27afae3b0a2f1326f131e460a31b2 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 27 Oct 2026 12:29:05 -0700 Subject: [PATCH 3/5] Add note that this isn't actually good enough for urllib/requests --- peps/pep-0818.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/peps/pep-0818.rst b/peps/pep-0818.rst index 64bb8101532..2d9e25246ba 100644 --- a/peps/pep-0818.rst +++ b/peps/pep-0818.rst @@ -62,7 +62,9 @@ content to the screen, to receive user input, to handle events, to access databases, etc. For instance, once Python has a JavaScript foreign function interface, it will be possible to support ``urllib`` on Emscripten. Downstream, supporting ``urllib3``, ``aiohttp``, and ``httpx`` requires the foreign function -interface. +interface. (By itself, this PEP is only enough to support the asynchronous APIs +defined by ``aiohttp`` and ``httpx``. All of ``urllib``, ``urllib3`` and +``requests`` expose synchronous APIs which require stack switching to support.) The fact that the Pyodide foreign function interface is coupled to Pyodide creates problems for other Emscripten-CPython distributions. For instance, From 7324ed2a6732472a5649bd575fae9902024c5bf6 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 27 Oct 2026 12:40:37 -0700 Subject: [PATCH 4/5] Reword a little more --- peps/pep-0818.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/peps/pep-0818.rst b/peps/pep-0818.rst index 2d9e25246ba..9af2e44f386 100644 --- a/peps/pep-0818.rst +++ b/peps/pep-0818.rst @@ -61,10 +61,11 @@ requires making calls into JavaScript: for example, it is required to display content to the screen, to receive user input, to handle events, to access databases, etc. For instance, once Python has a JavaScript foreign function interface, it will be possible to support ``urllib`` on Emscripten. Downstream, -supporting ``urllib3``, ``aiohttp``, and ``httpx`` requires the foreign function -interface. (By itself, this PEP is only enough to support the asynchronous APIs -defined by ``aiohttp`` and ``httpx``. All of ``urllib``, ``urllib3`` and -``requests`` expose synchronous APIs which require stack switching to support.) +supporting ``urllib3``, ``aiohttp``, ``httpx``, ``matplotlib``, ``bokeh``, and +other projects that do I/O requires the foreign function interface. (By itself, +this PEP is only enough to support the asynchronous I/O. All of ``urllib``, +``urllib3`` and ``requests`` expose synchronous APIs which require stack +switching to support.) The fact that the Pyodide foreign function interface is coupled to Pyodide creates problems for other Emscripten-CPython distributions. For instance, From fda6cebc8f43aadef4291b3c3dcffa7d06b3f653 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 27 Oct 2026 12:41:32 -0700 Subject: [PATCH 5/5] Reword --- peps/pep-0818.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/peps/pep-0818.rst b/peps/pep-0818.rst index 9af2e44f386..22919ea03b2 100644 --- a/peps/pep-0818.rst +++ b/peps/pep-0818.rst @@ -63,9 +63,9 @@ databases, etc. For instance, once Python has a JavaScript foreign function interface, it will be possible to support ``urllib`` on Emscripten. Downstream, supporting ``urllib3``, ``aiohttp``, ``httpx``, ``matplotlib``, ``bokeh``, and other projects that do I/O requires the foreign function interface. (By itself, -this PEP is only enough to support the asynchronous I/O. All of ``urllib``, -``urllib3`` and ``requests`` expose synchronous APIs which require stack -switching to support.) +this PEP is only enough to support asynchronous I/O. All of ``urllib``, +``urllib3`` and ``requests`` expose synchronous APIs and require stack switching +to support.) The fact that the Pyodide foreign function interface is coupled to Pyodide creates problems for other Emscripten-CPython distributions. For instance,