Skip to content

Commit

Permalink
gh-90473: Fail subprocess early on Emscripten/WASI (GH-92802)
Browse files Browse the repository at this point in the history
(cherry picked from commit db0b455)

Co-authored-by: Christian Heimes <christian@python.org>
  • Loading branch information
miss-islington and tiran authored May 14, 2022
1 parent dae3e2f commit 2bcae11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
else:
_mswindows = True

# wasm32-emscripten and wasm32-wasi do not support processes
_can_fork_exec = sys.platform not in {"emscripten", "wasi"}

if _mswindows:
import _winapi
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
Expand All @@ -97,13 +100,10 @@
"CREATE_NO_WINDOW", "DETACHED_PROCESS",
"CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
else:
if sys.platform in {"emscripten", "wasi"}:
def _fork_exec(*args, **kwargs):
raise OSError(
errno.ENOTSUP, f"{sys.platform} does not support processes."
)
else:
if _can_fork_exec:
from _posixsubprocess import fork_exec as _fork_exec
else:
_fork_exec = None
import select
import selectors

Expand Down Expand Up @@ -801,6 +801,11 @@ def __init__(self, args, bufsize=-1, executable=None,
encoding=None, errors=None, text=None, umask=-1, pipesize=-1,
process_group=None):
"""Create new Popen instance."""
if not _can_fork_exec:
raise OSError(
errno.ENOTSUP, f"{sys.platform} does not support processes."
)

_cleanup()
# Held while anything is calling waitpid before returncode has been
# updated to prevent clobbering returncode if wait() or poll() are
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`subprocess` now fails early on Emscripten and WASI platforms to work
around missing :func:`os.pipe` on WASI.

0 comments on commit 2bcae11

Please sign in to comment.