Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bcae11

Browse files
gh-90473: Fail subprocess early on Emscripten/WASI (GH-92802)
(cherry picked from commit db0b455) Co-authored-by: Christian Heimes <[email protected]>
1 parent dae3e2f commit 2bcae11

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Lib/subprocess.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
else:
7575
_mswindows = True
7676

77+
# wasm32-emscripten and wasm32-wasi do not support processes
78+
_can_fork_exec = sys.platform not in {"emscripten", "wasi"}
79+
7780
if _mswindows:
7881
import _winapi
7982
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
@@ -97,13 +100,10 @@
97100
"CREATE_NO_WINDOW", "DETACHED_PROCESS",
98101
"CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
99102
else:
100-
if sys.platform in {"emscripten", "wasi"}:
101-
def _fork_exec(*args, **kwargs):
102-
raise OSError(
103-
errno.ENOTSUP, f"{sys.platform} does not support processes."
104-
)
105-
else:
103+
if _can_fork_exec:
106104
from _posixsubprocess import fork_exec as _fork_exec
105+
else:
106+
_fork_exec = None
107107
import select
108108
import selectors
109109

@@ -801,6 +801,11 @@ def __init__(self, args, bufsize=-1, executable=None,
801801
encoding=None, errors=None, text=None, umask=-1, pipesize=-1,
802802
process_group=None):
803803
"""Create new Popen instance."""
804+
if not _can_fork_exec:
805+
raise OSError(
806+
errno.ENOTSUP, f"{sys.platform} does not support processes."
807+
)
808+
804809
_cleanup()
805810
# Held while anything is calling waitpid before returncode has been
806811
# updated to prevent clobbering returncode if wait() or poll() are
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`subprocess` now fails early on Emscripten and WASI platforms to work
2+
around missing :func:`os.pipe` on WASI.

0 commit comments

Comments
 (0)