summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-05-14 18:23:19 (GMT)
committerGitHub <noreply@github.com>2022-05-14 18:23:19 (GMT)
commitdb0b455ff482df68f331411bf22b3e5829398280 (patch)
treec5fcb4f8911ae1b6e80c97325eb62fb11674269a
parentd923fdf54bc97baece879179ba4971f632b9722b (diff)
downloadcpython-db0b455ff482df68f331411bf22b3e5829398280.zip
cpython-db0b455ff482df68f331411bf22b3e5829398280.tar.gz
cpython-db0b455ff482df68f331411bf22b3e5829398280.tar.bz2
gh-90473: Fail subprocess early on Emscripten/WASI (GH-92802)
-rw-r--r--Lib/subprocess.py17
-rw-r--r--Misc/NEWS.d/next/Library/2022-05-14-11-41-23.gh-issue-90473.kPdOZl.rst2
2 files changed, 13 insertions, 6 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 6e61cc2..e10b010 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -74,6 +74,9 @@ except ModuleNotFoundError:
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,
@@ -97,13 +100,10 @@ if _mswindows:
"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
@@ -801,6 +801,11 @@ class Popen:
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
diff --git a/Misc/NEWS.d/next/Library/2022-05-14-11-41-23.gh-issue-90473.kPdOZl.rst b/Misc/NEWS.d/next/Library/2022-05-14-11-41-23.gh-issue-90473.kPdOZl.rst
new file mode 100644
index 0000000..bf5ee54
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-05-14-11-41-23.gh-issue-90473.kPdOZl.rst
@@ -0,0 +1,2 @@
+:mod:`subprocess` now fails early on Emscripten and WASI platforms to work
+around missing :func:`os.pipe` on WASI.